How to add :autocmd to vim modeline?

Tag: vim , modeline Author: fm056610 Date: 2014-04-23

I am trying to add :autocmd BufWrite * make to modeline in vim, but it is not triggered. I see that the help says only set <options> can be used in modelines. Is there a way to achieve this effect, where I write a file to run make.

Other Answer1

Set your autocmd in your ~/.vimrc with a pattern that will match your file name. I would also suggest using augroup so it can be made to be re-sourced.

augroup my_project
  autocmd BufWrite /project/*.c make
augroup END

For more help see:

:h :au
:h :aug