Vim Tips Wiki

Open PDF files

Redirected from VimTip1356

1,624pages on
this wiki
Add New Page
Talk0 Share
Tip 1356 Printable Monobook Previous Next

created 2006 · complexity basic · version 7.0

This tip shows how to use Vim to view the text in a PDF document. That can be useful to use Vim to see the differences between the text in two versions of a pdf. You need to install xpdf (available on all major platforms) as it provides the pdftotext utility to read the text from a pdf file.


Put one of the following mappings in your vimrc:

:command! -complete=file -nargs=1 Rpdf :r !pdftotext -nopgbrk <q-args> -
:command! -complete=file -nargs=1 Rpdf :r !pdftotext -nopgbrk <q-args> - |fmt -csw78

These define the :Rpdf command to read the result of converting a pdf document to text. The text is read into the current buffer after the current line. The first reads the pdf with each paragraph as a long line, while the second wraps long lines (if the fmt utility is available).

For example, the following commands open a new tab page and read the text from a pdf document into the buffer.

:Rpdf example.pdf

See alsoEdit


You could create a ftdetect plugin and put instruction in it so you can just :edit filename.pdf and it'll set options for it. :help new-filetype

Ad blocker interference detected!

Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.

Also on Fandom

Random Wiki