When I need to understand code I usually print it and printed code is easier to understand if the code syntax highlighted. Before I learned this vim trick I usually either used vim built-in :TOhtml function and opened the syntax highlighted code in a web browser but it turned out that vim has another tric up the sleeve. The :hardcopy or :ha command.
First I need to set the printer in my .vimrc file:
set pdev=cp01 set printoptions=paper:A4,syntax:y,wrap:y, duplex:long
Now I can just use the :ha command print the highlighted document directly to the printer cp01.
Print to PDF
In the recent versions of Ubuntu Linux the Cups installation have had PDF printer device which basically just wrote the output to PDF file an put it in /home/username folder. So by using the follwing code I can make vim make a nice PDF version of the text.
set pdev=pdf set printoptions=paper:A4,syntax:y,wrap:y, duplex:long