I hate switching windows to refer some manual while coding.. completely breaks the flow. I was browsing through some vim tips, which had an entry for reading MS Word docs in vim and wanted to do the same with pdf files... and then decided to take it a notch higher. By adding the following entries to your .vimrc, you can read/write pdf files transparently, as if they were just regular files. Of course, you can also open these pdf files in regular pdf viewers.
Here's how to do it:
Here's how to do it:
- Get xpdf and cups-pdf. On Ubuntu this should do the trick:
sudo apt-get install xpdf cups-pdf
- cups-pdf prints the pdf files and saves them in ~/PDF/ by default. I am assuming that these settings wont be changed.
- Add the following lines to ~/.vimrc
autocmd BufReadPre *.pdf set ro nowrap
autocmd BufReadPost *.pdf silent %!pdftotext "%" -layout -q -eol unix -
autocmd BufWritePost *.pdf silent !rm -rf ~/PDF/%
autocmd BufWritePost *.pdf silent !lp -s -d"%"
autocmd BufWritePost *.pdf silent !until [ -e ~/PDF/% ]; do sleep 1; done
autocmd BufWritePost *.pdf silent !mv ~/PDF/% %:p:h