0

I currently have this autocommand in my vimrc: autocmd BufWritePost *.tex silent! execute "!pdflatex %" | redraw!

It compiles my current LaTeX file whenever I save with :w. However, a terminal window pops up every time I do so. silent! seems to ensure the window automatically closes after a few seconds, but it does not prevent it from opening in the first place.

  • What about using a plugin for compiling latex files which also parses errors & warnings and fills the quickfix list? You can configure vim for this on your own but you probably achieve this faster by using an existing plugin. I'd recommend vimtex. You can disable parts you do not want and only use the compile & quickfix functionality. – Hotschke Mar 28 '19 at 8:57
1

With vim 8, you could do something like

autocmd BufWritePost *.tex term ++close ++hidden pdflatex %

This should create a terminal buffer in vim running pdflatex, but keep it hidden and close it when the process exits.

But even better is to place your autocommand in a filetype plugin, so you can rely on that detection mechanism: ~/.vim/after/ftplugin/tex.vim can contain

autocmd BufWritePost <buffer> term ++close ++hidden pdflatex %
| improve this answer | |
  • Why is your latter suggestion better? – Harv Nov 9 '19 at 23:20
  • Organisation, and better grouping @Harv. I put filetype stuff in ftplugins – D. Ben Knoble Nov 9 '19 at 23:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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