By heavily templated I just mean it's easy to have something like this, which is just a trivial example I just made up:

#include <type_traits>
class a {};
bool operator<(a,a) { return true; };
bool b = std::is_same_v<decltype(a{} < a{}), bool>;
// poor little orphan──┘             └──married──┘

As you can see, provided things are set up in such a way that % jumps from </> to the (arguably) corresponding >/<, the % does jump, but between the wrong pair of angle brackets from the closing angle bracket to the less than operator.

Honestly I don't know if it's possible to distinguish between tempalate and "standalone" angle brackets without a "semantic-aware" parsing of the code, hence I'm asking the present question:

Is there a plugin which allows making this semantic-aware jumps between angle brackets?

  • 1
    without understanding the semantics of the code, it is difficult to handle this case and match the angle bracket correctly. – jdhao Nov 11 '20 at 10:10
  • 2
    You may also be interested in vim-matchup. – jdhao Nov 11 '20 at 10:12
  • @jdhao, interesting, and I think I'll use it, however it does not seem to provide a solution for the case I show here. I've created an issue here. – Enlico Nov 11 '20 at 20:38
  • Well... I wouldn't call it 100% "wrong". Even if you had an actual mismatched parenthesis (it doesn't really matter which type of bracket it is), something like ((test), and you press % while on the last parenthesis, where do you expect the cursor to go? To the first one or the second one? Both would be arguably wrong or right, depending on implementation/expectation. – ChatterOne Nov 12 '20 at 8:24
  • 1
    @Enrico You don't need classes for that to compile, a and b can simply be int and << is the bitwise operator to shift. But to be able to understand if those are classes, just int, and if there's a custom operator defined for <<, you need to compile the code. I don't think any plugin will ever do that. – ChatterOne Nov 12 '20 at 10:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.