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.
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\>"