1

I've installed vim-latex (aka latex-suite) ViM plugin and started to customize it. One thing I cannot find is the ability to perform an automatic recompilation every time the .tex file I'm editing is written on disk (i.e. every time I use the command :w of ViM). It would be very useful to me as I use zathura to view the pdf and it supports automatic detection of changes and it displays the updated pdf file.

Does anyone know how to achieve this effect with that plugin?

Thanks in advance.

2
  • 1
    Which command would you use to start a compilation otherwise? You can put something like the following in your .vimrc: autocmd BufWritePost *.tex <compilation command>, with <compilation command> replaced by the command starting your compilation. But instead of doing this, I use a custom mapping to save the file, which also runs make: nmap <leader>m :up<cr>:make<cr>, you could customize this to run your compilation command with nmap <leader>m :up<cr><compilation command>.
    – Skillmon
    Dec 24, 2019 at 14:38
  • To compile I use the shortcut \ll provided by vim-latex. Are there any ways to simply execute the command \ll every time I write? Something like autocmd BufWritePost *.tex <press \ll>?
    – LuxGiammi
    Dec 24, 2019 at 14:57

1 Answer 1

1

The standard binding used by the vim-latexsuite \ll does call Tex_RunLaTeX(). If you want VIM to do something every time after a file is written, you can use the autocmd BufWritePost, you can then give a filepattern that has to be matched by the written file to limit the scope of that autocmd, e.g., *.tex and then call functions of VIM. So you could put the following in your .vimrc:

autocmd BufWritePost *.tex call Tex_RunLaTeX()

If you don't want this to happen every time you save a file, it might be a good idea to create a custom binding that does save your file (if necessary) and then calls the function that runs LaTeX, e.g., you could use:

nmap <leader>m :up<cr>:call Tex_RunLaTeX()<cr>

This would create a mapping in normal mode that updates the file (so writes if there were changes) and after updating calls Tex_RunLaTeX(). With your current configuration that mapping would be on \m (<leader> is a configurable key, that is used for many bindings, it defaults to a backslash, you can change the <leader> by using let mapleader="<whatever>", that would also affect the bindings of vim-latexsuite).

2
  • Thanks a lot. Your solution works fine! Just a question: is there a way to avoid ViM showing the standard output of the command? I tried modifying your command into nmap <leader>m :up<cr>:silent call Tex_RunLaTeX()<cr> but it does not work.
    – LuxGiammi
    Dec 24, 2019 at 18:10
  • @LuxGiammi if silent doesn't work, I don't know.
    – Skillmon
    Dec 24, 2019 at 22:27

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .