Editing LaTeX, the Vim way

Uwe presented latexmk as its way of previewing LaTeX output while editing in Vim.

While I don't know latexmk myself, I'm using quite a lot LaTeX recently (my Ph.D. thesis is getting huuuge) and I'm co-maintaining vim-latexsuite in Debian. With vim-latexsuite what he wants can be achieved quite easily too.

I keep on editing in Vim and can exploit the following shortcuts (where <Leader> is usually mapped to backslash):

  1. <Leader>ll compile the current LaTeX source, the generated format depends on the value of g:Tex_DefaultTargetFormat (I use dvi, for a reason explained below);

  2. <Leader>lv fire up a viewer for the compiled format, in my case this runs xdvi;

  3. <Leader>ls move the DVI viewer to the point the cursor is currently at in Vim, highlighting (in xdvi) with a rectangle the current paragraph (believe me, this is amazing);

  4. CTRL+Mouse Click (this in xdvi) do the opposite of (3), i.e. move Vim to the point in the LaTeX source file corresponding to where we clicked in xdvi.

I don't really understand why Uwe want to see working previews in PDF format, to me PDF is just the final output. DVI is much better (especially for (3) and (4) above, but also because it takes less time to be generated).

Oh, and of course vim-latexsuite is able to do a lot more, like deciding whether LaTeX needs to be run again to fix dangling references, use the quickfix window to jump to compilation error, and so on ... End of the SPAM :-)

PS these are my latex-specific vim settings from my ~/.vim/after/ftplugin/tex.vim

setlocal tw=80
setlocal ts=8
setlocal sts=1
setlocal sw=1
setlocal iskeyword+=\\
setlocal makeprg=make
setlocal keywordprg=:help
"setlocal formatoptions+=a
setlocal spell
vmap ,b "zdi\textbf{<C-R>z}<ESC>
vmap ,e "zdi\emph{<C-R>z}<ESC>
vmap ,t "zdi\texttt{<C-R>z}<ESC>

  " Latex-Suite
let g:Tex_CompileRule_dvi = 'latex -interaction=nonstopmode -src-specials $*'
if v:servername != ""
 let g:Tex_ViewRule_dvi = 'xdvi -editor "vim --servername ' . v:servername . ' --remote +\%l \%f"'