vim-matchup
vim-matchup copied to clipboard
Is it possible to match corresponding angle brackets in template C++ code?
Is your feature request related to a problem? Please describe. Matching corresponding angle brackets in C++ template code. The following toy example is a demo of the issue:
#include <type_traits>
class a {};
bool operator<(a,a) { return true; };
bool b = std::is_same_v<decltype(a{} < a{}), bool>;
I've also asked a question on vi.stackexchange.
Describe the solution you'd like Matching corresponding angle brackets in C++ template code.
Describe alternatives you've considered Does one even exist? However, I'm asking for this feature, but I suspect it might be impossibile to implement it without a semantic-aware strategy.
Additional context Related: #69
You can try this. It's not perfect, but may work.
let g:matchup_matchpref = {'cpp': {'template': 1}}
Doing it properly is going to require vim to understand syntax much better. I have a lot of ideas about this but no specific timeline.
I'm not sure recognizing the syntax perfectly would actually solve the problem. For instance, in the following B<i>b; has a totally different meaning depending on the different meaning of B, i, and b.
class A {};
A operator<(A,A) { return A{}; };
A operator>(A,A) { return A{}; };
template<typename T>
class B {};
class i {};
int main() {
{
B<i>b; // pair of angle brackets
}
{
A B, i, b;
B<i>b; // two unrelated comparison operators
}
}
Indeed, % jumps between < and > on both lines, even if I've set let g:matchup_matchpref = {'cpp': {'template': 1}}.
Based on this example, I think the current behavior is close to the best that we can do, so I'll close this issue for now.
The neovim/tree-sitter version is slightly smarter but has similar bad parses. C++ after all is highly context sensitive..