Suppose I am editing a file.tex. How would I open file.pdf in zathura (or any pdf viewer) from vim?
I understand how to reference file.tex using '%' but I'm not sure how to reference file.pdf.
Vi and Vim Stack Exchange is a question and answer site for people using the vi and Vim families of text editors. It only takes a minute to sign up.Sign up to join this community
You can do something like this
let main = expand('%') let pdf = fnamemod(main, ':r') . '.pdf'
The above steps may of course be combined into a single step. Given the above, you can now open the file in zathura as follows:
silent execute 'zathura' . pdf
I propose you combine all of the above in one function, which makes it easy to map. E.g.:
nnoremap <silent> \lv :call OpenInZathura()<cr> function! OpenInZathura() let main = expand('%') let pdf = fnamemod(main, ':r') . '.pdf' silent execute 'zathura' . pdf endfunction
I'll take the liberty of mentioning my LaTeX-plugin vimtex, which has support for zathura and other pdf viewers. For zathura, vimtex sets up both forward and backward search with synctex. It also handles more complex cases such as multifile projects.