There's posts on SO that explain how to do it in general or on files of a particular type but I would like to restrict it to when I'm inside my project directory.

I can run a script to determine whether I am. How I can I wire it up with vim?

In other words, how do I do something like?:

if  !myscript >/dev/null 2>&1 "doesn't work
    autocmd BufWritePost <buffer> make

2 Answers 2


Another (untested) approach :

:autocmd BufWritePost <buffer> make and

:let &makeprg="if ! myscript >/dev/null 2>&1 ; then make ; fi"

I use let &makeprg="..." instead of set makeprg ... to avoid the ugly \-es.

  • It's not very pretty but this general approach is workable. Thanks. Commented Oct 3, 2017 at 12:28

If I understand your question correctly then this might help:

:autocmd BufWritePost <buffer> if !system ("myscript >/dev/null 2>&1") | make | endif

  • Thanks but this doesn't appear to do it. If I replace myscript with true or /bin/true it runs, but it also runs with false o /bin/false, which shouldn't happen. Commented Oct 3, 2017 at 11:54
  • system() returns command's output, not its exit code. This could work: :autocmd BufWritePost <buffer> call system('myscript >/dev/null 2>&1') | if v:shell_error | make | endif
    – xaizek
    Commented Oct 3, 2017 at 13:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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