Reputation: 4976
I created a vim script to allow easy insertion of snippets when I code. I use placeholders of the form <#placeholder#>
and loop through them. I would like to highlight the placeholders as comments so vim doesn't try to color those blocks :
syntax match abridgePlaceholder "<#.[^#]*#>"
highlight link abridgePlaceholder Comment
This works fine in a live session, but I tried to package it in a syntax file inside .vim/syntax
but it doesn't work. I think vim doesn't load this syntax file at runtime.
I also tried putting that syntax in my .vimrc
, but it didn't work neither...
So I would like that syntax to be applied to all filetypes. Is there a way to do this?
Upvotes: 1
Views: 293
Reputation: 172540
Yes, this is possible. You need to hook into the Syntax
event; this gets fired whenever the filetype / syntax changes. You can place this into your ~/.vimrc
, but after :syntax on
, so that the default syntax handling (which clears existing stuff) comes first:
:autocmd Syntax * syntax match abridgePlaceholder "<#.[^#]*#>"
The highlight needs to be defined only once:
:highlight link abridgePlaceholder Comment
The syntax additions may interfere with the existing filetype's syntax, adding containedin=ALL
may alleviate the problem, but there's no perfect solution.
Alternatively, you could use :match
/ call matchadd()
, which is completely separate from syntax highlighting, but this needs to be defined for each window (again, using :autocmd
s).
Upvotes: 3