VIM: Can I view a pdf file in a split window?

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 create notes while reading pdf. I write my own notes, but often copy text from pdf, so smooth copying would be nice. Currently I need alt + tab to view PDF files, 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 that it is possible without a mouse, holding hands in the "home row" and not needing an external alt + tab program to ...

Ideally, I would like the pdf file to appear as intended. If this is not possible, I will try how pdf will be displayed as a text representation using some plugin.

+4
source share
2 answers

Vim is a text editor, so it only edits text. So yes, you can edit the PDF at the binary level, but you cannot view the contents of the PDF in the way they should be displayed. You can use the xpdf package to convert PDF to text first and then view it, but the results are not perfect. However, there are some useful auto-commands that allow you to open non-text files with their default program when you "open" them in vim. I use them:

 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 are using a Linux distribution. The any2pdf command is a script I use , which converts these files to PDF before opening them. You can edit this if you just want to open everything with the default program. For instance,

 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 can also look in window managers, such as dwm or ratpoison , that come close to what you ask.

+6
source

You can install a plugin that will allow you to view text in pdf, however I am not familiar with gVim, so I do not know if this wiki page is applicable to you.

+2
source

All Articles