Note
I am using the local vim plugin that allows me to use a project-specific .vimrc file, in general it works fine and as you’d expect.
Background
I work with Silverstripe, and therefore have to work with Silverstripe templates, which are *.ss files, however by default vim assigns *.ss to scheme files. Now I only use Silverstripe for one project, and have been using the html filetype set in my project-specific .vimrc for highlighting, however after encountering a few bugs, I figured that I would add the highlighting for *.ss files in an htmlss.vim file (using html.vim as a base, i just added the template rules near the end). After a bit of trial and error I got it working and highlighting properly, however i have encountered a strange bug…
Question
Using this project .vimrc:
augroup filetypedetect
autocmd! * *.ss
autocmd! BufEnter *.ss setf htmlss
augroup END
Everything works fine, however, using this .vimrc:
augroup filetypedetect
autocmd! * *.ss
autocmd! BufEnter,BufRead,BufNewFile *.ss setf htmlss
augroup END
The syntax highlighting fails, it sets the filetype correctly, but the highlighting goes screwy.
I guess I want to know why version 1 works, but version 2 doesn’t, despite nothing else changing.
Addendum
After a little more investigation, i have found that removing autocmd! * *.ss makes the second one work, only if i remove ! from the autocmd! BufEnter,BufRead,BufNewFile *.ss setf htmlss. i.e.
augroup filetypedetect
autocmd BufEnter,BufRead,BufNewFile *.ss setf htmlss
augroup END
works but
augroup filetypedetect
autocmd! BufEnter,BufRead,BufNewFile *.ss setf htmlss
augroup END
and
augroup filetypedetect
autocmd! * *.ss
autocmd BufEnter,BufRead,BufNewFile *.ss setf htmlss
augroup END
do not.
Again, my question is why these difference occur, i have a working implementation now, so i am not interested in any investigation. I don’t want solutions as i have no problem.
This is probably caused by your syntax file conflicting with itself when applied multiple times. One of the first lines in the syntax file is probably
syntax enable, which enables syntax without changing any of the current highlight settings. Per the docs:So, an adequate “solution” should be to change
syntax enabletosyntax onin the syntax file.