问题
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.
回答1:
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.
回答2:
You can install a plugin that will allow you to view the text in a pdf, however I'm not to familiar with gVim so I don't know if this wiki page is applicable to you.
来源:https://stackoverflow.com/questions/11916898/vim-is-it-possible-to-view-pdf-file-in-a-split-window