Vim Tips Wiki
Advertisement
Tip 1356 Printable Monobook Previous Next

created October 8, 2006 · complexity basic · author Erez Volk · version 5.7


Inspired by the excellent VimTip790, here's how to view PDF files in Vim.

Get the free Xpdf from (http://www.foolabs.com/xpdf/download.html). For Win32 specifically, you can get the zip file and just extract pdftotext.exe.

Now add the following to your vimrc:

autocmd BufReadPre *.pdf set ro
autocmd BufReadPost *.pdf %!pdftotext -nopgbrk "%" -

And just like for MS-Word files, this allows you to use Vim to diff two pdf files very nicely.

Comments

If you happen to be on Unix or have the fmt utility, a slight improvement is:

autocmd BufReadPost *.pdf %!pdftotext -nopgbrk "%" - |fmt -cw78

Or, better still:

autocmd BufReadPost *.pdf %!pdftotext -nopgbrk "%" - |fmt -csw78

Add silent and you don't need to press enter:

autocmd BufReadPost *.pdf silent %!pdftotext -nopgbrk "%" - |fmt -csw78

You may want to call pdftotext with parameter -layout -- tries to maintain the original layout of pages. This doesn't compress all the page into one chunk of text.


Win32 users: pdftotext comes as part of the CygWin Suite http://www.cygwin.com/

Please don't install cygwin just for pdftotext. Use the link to the xpdf-files, as the author suggests. There is a pdftotext for Win32 as well.


Advertisement