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.

0

1 Answer 1

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.

4
  • :syntax match Error "ur_term" works. However, how to make it case insensitive? Thanks. Commented Aug 5, 2015 at 22:18
  • Updated answer accordingly (\c flag).
    – VanLaser
    Commented Aug 6, 2015 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. Commented Aug 8, 2015 at 5:30
  • This one could be used for B/W printing, I think: github.com/plan9-for-vimspace/acme-colors
    – VanLaser
    Commented Aug 8, 2015 at 16:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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