How to print from Vim in Linux

Printing from Vim

November 6, 2020 - 1 minute read -
Linux

Back after a long hiatus, what a year 2020 has been and we’re not even done with it yet!, anyway, life as people say must go on and so, I am back with another Linux quick tip.

This time, I’m going to show how you can print from the Vim interface on a Linux system, unlike some other programs, vim cannot print directly to PDF and so one needs to first print to a PostScript file format (.ps) and then convert the PostScript file into PDF.

To print to a PostScript file from console Vim:

:hardcopy > file.ps

and then convert the PostScript file by using the ps2pdf program, forexample, using the file.ps file above, we can convert it to PDF by running the following command in a terminal:

ps2pdf file.ps

Running the above command will output a PDF file named file.pdf which can be opened with any PDF reader.