I'm new to Vim and it's just fantastic! Now I would like to set up the Latex-suite with reverse searching and found this easy way by compiling to xdvi. But sometimes, I need the .pdf.

What I would like:

  • \ld : save, compile to .xdvi and open the default .xdvi viewer
  • \lv: save, compile to .pdf and open the default .pdf viewer

How can I do this? Is it possible to save the multi-file LaTeX-project?

1 Answer 1


You should take a look at this Wikia page about options to compile LaTeX from Vim. The vim-latex plugin should cover all your needs (e.g. Multiple file LaTeX projects), you can find the full documentation here or with :help latex-suite from within Vim.

An alternative method is to tweak the &makeprg option in order to change the program used by the :make command. From the same article; if using pdflatex, add this to ftplugin/tex.vim:

let b:tex_flavor = 'pdflatex'
compiler tex
set makeprg=pdflatex\ \-file\-line\-error\ \-interaction=nonstopmode
set errorformat=%f:%l:\ %m

See :h :_% and :h :_# for their special meaning in &makeprg. Note that &errorformat is used to describe the output, available in the quickfix window after each run. Here is how those are "dynamically" defined in the plugin for LaTeX-suite.

Once you are able to execute :make successfully, just add a mapping to save, compile and open (this assumes the file is created with the same location and name, and that open is an actual PDF viewer in your PATH):

:nnoremap \lv :w<CR>:make<CR>:!open expand('%:r').pdf<CR>

For more:

  • :h :nnoremap
  • :h expand()
  • :h filename-modifiers
  • Thank you! I've changed to vimtex because it's supporting inverse search with zathura out of the box.
    – Theova
    Sep 17, 2017 at 16:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.