To accomplish this you'll need to write an expression that matches your
var: TypeN situation.
let type1Match = '\(.*\): Type1'
You can find all matches and store them in a list by using
silent execute "vimgrep /" . a:regex . "/j %"
return split(join(map(copy(getqflist()), 'matchlist(v:val.text, a:regex)')))
This function returns a list containing all match cases or and empty list if none are found. To find all cases of
var: Type1 use
The last step is to execute
syntax match on this list.
execute "syntax match type1Keyword \"\\<\\(" . join(FindMatches(type1Match), '\|') . "\\)\\>\""
You can add this into your syntax file and when the file is saved and loaded it will execute.
One thing to note. This will highlight all cases of the match value. In your example the
a: Type1 and in
And now I will talk about a and b will both be highlighted. You can make your syntax highlighter smarter by highlighting the specific
a: Type1 situation differently but requires a match case of