4

Is there some program that can parse vim syntax highlighting scripts and colorize code for export to the shell? Basically I am looking for cat/less with shell highlighting that draws its syntax from vimscript definitions, so I can define my own.

addendum: A preferred solution would be a program that outputted to stdout directly, like cat, so i could pipe to less or whatever i would want to use it for

Justin L.
  • 1,209

2 Answers2

5

For use as a pager, Vim comes with $VIMRUNTIME/macros/less.sh. See here on the Vim Tips Wiki. There's also a plugin alternative, vimpager, and you'll probably find more on the Web.

Ingo Karkat
  • 23,523
4

I answered a similar question on StackOverflow:

Matthew Wozniski wrote a script called vimcat.sh that does this with Vim. His version is at https://github.com/godlygeek/vim-files/blob/master/macros/vimcat.sh. I've made a few modifications to it (if memory serves, the modifications allowed it to run on my Mac OS X system; I know the substitution of /dev/fd/9 for /proc/self/fd/9 had that purpose); see my gist at https://gist.github.com/4090959.

I believe both versions of the script have trouble with returning to default background color if Vim's highlighting changes the background.