11

I would like vim to do this in order to have syntax highlight as set up in vim (or without need for extra tools). So instead to use cat file | <some_sh_tool> I would use vim +"some_opts" +"..." +q file. The problem is that vim restores previous screen upon exit, but using some remote access tools this didn't happen so it was basically working as cat with syntax highlight.

So, is this possible ?

EDIT

Thinking more about this I think this is great thing to have. Apart from syntax highlighting other features of vim could be used while displaying file content, like line numbers, white space, wrapping,etc... especially within script and because vim is omnipresent.

9

You can disable the alternate screen, by telling that the code to enable it for this terminal is the empty string like:

vim --cmd 'set t_ti= t_te=' ...

But you'll find you need more. Try:

vim --cmd 'set t_ti= t_te=' +redraw +q file

as a start.

  • It may pay to explain how to create an alias for the final command. – cjh Dec 22 '12 at 21:13
  • @cjh: that depends on the user's shell. – Bananguin Dec 22 '12 at 22:23
  • 1
    alias catx='vim --cmd "set t_ti= t_te=" +redraw +q' then simply run catx infile – Rahul Patil Dec 22 '12 at 22:32
  • you might also want to add +"colo colorscheme" before the +redraw. – peterph Dec 22 '12 at 22:52
  • 2
    Not good. It will show first page and exit. I need it to show all of the lines. Adding +$ before redraw shows first and last page only. – majkinetor Dec 22 '12 at 23:19
2

You might want to take a look at enscript - it has syntax highlighting styles for a couple of languages and is intended to be used as a filter, and the output is not limited to just ANSI escape formatting sequences - it can also output PostScript, HTML or RTF.

  • 1
    I have vim setup the way I want already - colors, languages etc... some of the sh features for rare languages are custom - Csound, AutoHotKey, etc... I don't wont to write config files for another tool again. – majkinetor Dec 23 '12 at 14:01
  • @majkinetor sure, it all depends on what exactly you want to use it for. – peterph Dec 23 '12 at 19:40
2

I found exactly what I needed in a package called vimpager.

It ships with vimcat utility.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.