Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VIM: Is it possible to view pdf file in a split window?

Tags:

vim

pdf

I would like to view a pdf file in a split window using gVim, does anyone know if this is possible? How?

Some details: I just recently started using vim and use it to make notes, while reading a pdf. I write own notes, but quite often I copy text from pdf, so smooth copying would be nice. Currently I need to alt+tab for pdf viewer, go to mouse or arrow keys, select text, copy, alt+tab back to vim. Of course this is not a huge task, but using vim I feel it could be possible without mouse, keeping hands at "home row", and not needing external program alt+tab to...

Ideally I would like pdf to be shown as it is supposed to be. If that is not possible, I will try how pdf shows as text representation using some plugin.

like image 594
JoonasS Avatar asked Aug 11 '12 19:08

JoonasS


People also ask

Can you read a PDF in Vim?

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.

How do I view two PDF files side by side?

Open a pdf file and click 'View' on the main menu > Select 'Split View'. Open the files in two tabs and click the area between the tabs. Click the View settings button on the top toolbar. Drag and drop one tab over another one to enable the split mode.


1 Answers

Vim is a text editor, so it only edits text. So, yes you can edit the PDF on a binary level, but no you can't view the contents of the PDF as they are meant to be displayed. You can use the xpdf package to convert the PDF to text first and then view that, but the results aren't perfect. However, there are some useful autocommands to allow you to open non-text files with their default program when you "open" them in vim. I use these:

augroup nonvim
   au!
   au BufRead *.png,*.jpg,*.pdf,*.gif,*.xls* sil exe "!open " . shellescape(expand("%:p")) | bd | let &ft=&ft
   au BufRead *.ppt*,*.doc*,*.rtf let g:output_pdf = shellescape(expand("%:r") . ".pdf")
   au BufRead *.ppt*,*.doc*,*.rtf sil exe "!/usr/local/bin/any2pdf " . shellescape(expand("%:p"))
   au BufRead *.ppt*,*.doc*,*.rtf sil exe "!open " . g:output_pdf | bd | let &ft=&ft
augroup end

Instead of !open you can use !xdg-open if you're using a Linux distro. The any2pdf command there is a script I use that converts those files to a PDF before opening them. You can edit this if you just want to open everything with its default program. For example,

augroup nonvim
   au!
   au BufRead *.png,*.jpg,*.pdf,*.gif,*.xls*,*.ppt*,*.doc*,*.rtf sil exe "!open " . shellescape(expand("%:p")) | bd | let &ft=&ft
augroup end

You might also want to look into window managers like dwm or ratpoison, which come pretty close to what you're asking for.

like image 197
Conner Avatar answered Sep 28 '22 08:09

Conner