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