sponsor Vim development Vim logo Vim Book Ad

intermediate Tip #111: Printing with syntax highlighting independent of your normal highlighting

 tip karma   Rating 22/10, Viewed by 2290 

Read and edit this tip on the Vim tip wiki. The wiki may have a more recent version of this tip.

created:   September 7, 2001 9:50      complexity:   intermediate
author:   Aric Blumer      as of Vim:   6.0

I have found it undesirable to use :hardcopy directly because it uses the current syntax highlighting to determine how to print the text.  For example, I like to print comments in italics, but I don't like italic fonts on the screen. This tip will show you how to set up a colorscheme for printing and use it only when you print.

I copied an existing colorscheme to ~/.vim/colors/print.vim, and changed all the lines like this:

  highlight Normal ctermbg=DarkGrey ctermfg=White guifg=White guibg=grey20
to this:
  highlight clear Normal

Then I set the syntax groups how I wanted them to be printed on the printer:

  highlight Comment        term=italic    cterm=italic    gui=italic
  highlight Constant       term=bold      cterm=bold      gui=bold
  etc....

I then defined the following command in my .vimrc file:

command! -nargs=* Hardcopy call DoMyPrint("<args>")

And, finally, I defined this function in my .vimrc:

function DoMyPrint(args)
    let colorsave=g:colors_name
    color print
    exec "hardcopy ".a:args
    exec 'color '.colorsave
endfunction


After this is complete, you can do:
   :Hardcopy > /tmp/out.ps
or just
   :Hardcopy
(Note the capital H)

 rate this tip  Life Changing Helpful Unfulfilling 

<< text->html table converter. | Back and forth between indented lines again >>

Additional Notes

Anonymous, September 7, 2001 14:06
This does, BTW, assume that you are already using a colorscheme.
If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to the maillist. Help Bram help Uganda.
   
Sponsored by Web Concept Group Inc. SourceForge.net Logo