9

I'm using set matchpairs+=<:> with my C++ code, and it works great. But there are some cases where it is not quite there, like this C++ code:

#include <type_traits>
template<int X> typename std::enable_if<(X>9),int>::type func() { return 5; }
int main() { func<10>(); }

Here, if you put the cursor on the < after enable_if, the > in X>9 will be highlighted. Of course it makes sense from the perspective of Vim, which isn't a C++ compiler nor an IDE. But is there any easy way to make it not match pairs broken by non-closed parentheses? I.e. I'd like <()> to match the closing angle bracket, and <(>) not to.

Ruslan
  • 475
  • 2
  • 12
  • just curious, are you working with matchit ? https://github.com/tmhedberg/matchit, since it often solves this kind of problems, but i am not sure if it will help in your case – B.G. Feb 13 '17 at 15:05
  • @DoktorOSwaldo no, just plain vim. – Ruslan Feb 13 '17 at 15:43

1 Answers1

1

matchit will most probably not do this for you. You probably want to write a small wrapper function for %, which identifies the character under your cursor with:

let curChar = char2nr(matchstr(getline('.'), '\%' . col('.') . 'c.'))

followed by a couple of simple nested tests such that:

test-1: if curChar is not `<`, then
     act simply the way `%` would
else 
    test-2:  if whatever lies between current `<` and following `>` contains one of ( or ) or { or } or [ or ], then
        do not jump or highlight
    else
        jump or highlight

which means , get scripting in vim ...

Let us know how this goes.

Cbhihe
  • 241
  • 2
  • 10