Vim - wait for file syntax check before exit

256 views Asked by At

I am using Vim 7.4 on MacOSX with scrooloose/syntastic plugin to edit YAML files.

I have mapped F11 to:

:wa<CR> 
  • the file is checked for yaml validity (it uses node and js-yaml if I recall correctly).
  • I get an indication (not perfect) of where any error might be.

I have also mapped F12 to:

:wa<CR>:xa<CR> 

Now to me... since F11 does a js-yaml check and reports errors, F12 should also do the same thing since the mapping is ALMOST identical.

My problem is that before js-yaml file checker can return with any errors, Vim will exit. I don't know how to have it wait for js-yaml to return.

Any suggestions?

In Vim I did a quick ":help pause" → to no avail.

1

There are 1 answers

0
lcd047 On

The simple solution is to set g:syntastic_check_on_wq to 1 and to map your F12 to :wqa<CR>.

The more complicated (but smoother) solution involves writing the buffers, then checking all of them for syntastic errors. You'll need some VimL-fu for that though.

Also, please note that syntastic doesn't work very well when checking several files at the same time (which you do when you run :wa). This is related to limitations in Vim API.