Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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 ?


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.

share|improve this question
use GNU screen. – jordanm Dec 22 '12 at 18:08
its not exactly the same, you can't use it within script, besides, sometimes you can't choose. – majkinetor Dec 22 '12 at 23:24
Possible duplicate: stackoverflow.com/questions/13408134/… – echristopherson Dec 24 '12 at 0:07

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.

share|improve this answer
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
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
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

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.

share|improve this answer
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
up vote 1 down vote accepted

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

It ships with vimcat utility.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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