10

When we search a pattern in vim, the matches are usually highlighted. However, when we print it out, the highlights disappear. I tried both :hardcopy > my_file.pdf and :TOhtml. Neither retains the highlight.

Is there any way that I can output the document with matched patterns highlighted to a pdf file?

I'm using GVim 7.4 on a Win 7 machine.

13

Try something like this:

:syntax match Error "yourterm"

or (to ignore case and match "Yourterm", "YOURTERM", "yourTerm" etc.):

:syntax match Error "\cyourterm"

... and print with hardcopy - the term should be highlighted using the Error highlight rules. (see also this).

Here's a pdf sample printed from my vimrc, using :syntax match Error "Plug":

enter image description here

If the search term is already highlighted using current filetype syntax rules (so the previous command doesn't have any effect), and if you don't have a problem printing the text without those (in black-and-white, so to speak), then: :set ft= and then syntax match Error "yourterm". You'll get black text on white background, with a touch of (probably) red - the highlighted matches.

  • :syntax match Error "ur_term" works. However, how to make it case insensitive? Thanks. – user3813057 Aug 5 '15 at 22:18
  • Updated answer accordingly (\c flag). – VanLaser Aug 6 '15 at 8:49
  • I remember a colour scheme specifically designed for printing, from a few years ago. Not sure what happened to it though. Personally I'm using a2ps for printing code, it fills the bill pretty well. – Sato Katsura Aug 8 '15 at 5:30
  • This one could be used for B/W printing, I think: github.com/plan9-for-vimspace/acme-colors – VanLaser Aug 8 '15 at 16:25

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.