Reputation: 946
I have a syntax highlight for cpp to highlight STL algorithms, one line is
syn keywork cppSTL find
My problem is that on a project that I am working, there are a number of classes with a method named find
which are getting highlighted, and I want it only highlighted for STL calls.
So I decided to change the previous line to:
syn match cppSTL /[^.>:]\<find\>/ms=s+1
syn match cppSTL /\<std::find\>/ contains=cppScope
syn match cppScope /::/
hi clear cppScope
And it works most of the time. However if fails in this line:
vector<string>::iterator i = find(find(x.begin(), x.end(), val), x.end(), term);
^^^^
The first find
is highlighted correctly, but the second fails. My limited knowledge of vim regex says it should match, but I can't figure out why it doesn't.
Upvotes: 4
Views: 1690
Reputation: 946
I got it!
The problem is that my regex required a char behind find, and inside the parenthesis, the open parenthesis had already been matched, invalidating my regex.
It works if I replace the first line with:
syn match cppSTL "[^.>:]\@<=\<find\>"
Upvotes: 0
Reputation: 31429
This might be what your looking for. It highlights all words find
that are on a line that also contains a ::
before it.
syn match cppSTL /\(::.*\)\@<=\<find\>/
If this isn't what you are asking for please tell me.
Upvotes: 2