Vim to print file on terminal and exit

vim

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.

Best Answer

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.

Related Question