2

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
endif
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.

1
  • It's not very pretty but this general approach is workable. Thanks. – PSkocik Oct 3 '17 at 12:28
0

If I understand your question correctly then this might help:

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

2
  • 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. – PSkocik Oct 3 '17 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 Oct 3 '17 at 13:55

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.