Define a different file type for bolt plans. In ~/.vim/ftdetect/puppet.vim
change the line
au! BufRead,BufNewFile *.pp setfiletype puppet
to something like this:
au! BufRead,BufNewFile *.pp if search('^plan ', 'n') == 0 | setfiletype puppet | else | setfiletype bolt | endif
The search()
function returns the line number of the next line matching the given expression (the parameter 'n'
tells vim to not move the cursor to that line). A result of 0 means that no matching line was found (i.e. you have a Puppet manifest) and the file type is set to puppet
. Otherwise the file type is set to bolt
. Since makeprg=puppet_validate.sh
is defined only for the file type puppet
the command is not being run when saving files with the type bolt
.
If you want to keep the syntax highlighting, copy ~/.vim/syntax/puppet.vim
to ~/.vim/syntax/bolt.vim
(the name of the file must match the file type you set for Bolt plans).