Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

If I execute the following commands from within a vim session that's visiting a file of code, the resulting hardcopy is syntax highlighted in color:

:syntax on
:hardcopy >/path/to/hardcopy.ps

But if I try the same sequence of commands from the command line (Unix shell), the resulting hardcopy is not color-highlighted (I get just black text, sometimes bold, or underlined, etc., on a white background):

% vim -c ':syntax on' -c ':hardcopy >/path/to/hardcopy.ps' -c quit /path/to/original

Any ideas on how to fix this problem?

share|improve this question
add comment

1 Answer

I suspect that what may be at issue here is Vim's colorization is a kind of hack which is integrated with the display code. Note that, for instance, when you're jumping around in a large file, sometimes the coloring will be wrong, because Vim tries not to process the entire file in applying its hierarchical "region" pattern matches. Also, if your terminal doesn't support colors, then Vim will not print color or generate colorized HTML, even though those destinations have nothing to do with the terminal.

I once tried to turn Vim into a back end for doing on-the-fly syntax highlighting under CGIT, for viewing files in a GIT repository. I tried numerous hacks to try to get Vim to produce output in batch mode, but in the end I gave up.

But I stopped short of trying to use a utility like expect. Scripting Vim with expect is something that might work, provided you also lie to it, and tell it that it's talking to a color Xterm.

share|improve this answer
add comment

Your Answer

 
discard

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.