How can I tell vim to compile a document on save?

11

4

I'd like that vim automatically compiles a lout document (similar to LaTeX) every time I save the document.

Is there a possibility to add such functionality to save? (Preferably without using anything else than :w to save.)

Georg Schölly

Posted 2011-04-11T19:35:52.987

Reputation: 1 146

See also the same question on the TEX Stack Exchange: https://tex.stackexchange.com/questions/2672/how-to-use-the-vim-quickfix-mode-for-latex

– feuGene – 2019-04-30T00:39:10.540

Answers

12

You can do that with an autocommand. I don't have one that loads automatically, but if I know I'm going to be going through the edit-compile-edit cycle for a while with one file, I'll execute something like this at the Vim command line:

:au BufWritePost * make

You can replace make with whatever build or run command is appropriate.

garyjohn

Posted 2011-04-11T19:35:52.987

Reputation: 29 085

2

@garyjohn 's answer is correct.

and let me add an example on how to run multiple compile on coffeescript:

# add these lines to your .vimrc file (~/.vimrc in my pc)
autocmd BufWritePost,FileWritePost *.coffee :silent !coffee --compile --join appstore/static/javascripts/angular/controllers.js file1.coffee file2.coffee

autocmd BufWritePost,FileWritePost *.coffee :silent !coffee --compile appstore/static/javascripts/angular/app.coffee appstore/static/javascripts/angular/directives.coffee appstore/static/javascripts/angular/filters.coffee appstore/static/javascripts/angular/services.coffee

Siwei Shen 申思维

Posted 2011-04-11T19:35:52.987

Reputation: 617