History
Article Edit this page Discussion

Printing with syntax highlighting independent of your normal highlighting

From Vim Tips Wiki

Jump to: navigation, search

[edit] Duplicate tip

This tip is very similar to the following:

These tips need to be merged – see the merge guidelines.

Tip 111 Previous Next Created: September 7, 2001 Complexity: intermediate Author: Aric Blumer Version: 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)

[edit] Comments

This does, BTW, assume that you are already using a colorscheme.


Rate this article:

Share this article:

Hubs Highlights International Sites Wikia messages
Entertainment
Gaming
Cartoons & Comics
Science Fiction
Hobbies
Sports
See all...
Grand Theft Auto
Doctor Who
Legend of Zelda Wiki
Terminator Wiki
Everquest II Wiki
Mystery Science Theater 3000
German
Spanish
Chinese
Japanese
More...
Wikia is hiring for several open positions
Send this article to a friend
"Printing with syntax highlighting independent of your normal highlighting"
 
 
Hi!

I thought you'd like this page from Wikia!

http://vim.wikia.com

Come check it out!
Send confirmation