I am trying to learn VIM, buy I noticed when I try using the % command to go to a matching bracket, VIM sometimes finds the correct matching bracket and is sometimes way off. Has anyone ever come across this with a solution?
+4
A:
This happens because:
- You have an actual syntax error with a mismatched paren or curly brace somewhere.
- You have a value in
cpoptions
that prevents semi-intelligent brace matching. Look up:help cpoptions
and:help %
. - You have something too sophisicated for plain old Vim matching to handle. Try installing the
matchit
plugin, which may help. Common culprits are braces inside comments or regexes.
JSBangs
2009-12-14 20:25:36
there is a 4th non-obvious option: I had a "syntax error" in a comment.
ldog
2009-12-15 19:51:23
Comments were meant to be included in #3. I should have been more explicit, because braces in comments is a common scenario that I had in mind when I wrote #3.
JSBangs
2009-12-15 19:53:09
A:
Apparently, vim parses brackets even in comments, which was happening in my case, I had a non-complete bracket pair commented out, meaning vim did not find bracket pairs correctly but the compiler had no problem, hence my confusion.
ldog
2009-12-15 19:50:15
Yeah, comments and regexes are the usual culprits when I have this problem. This was meant to be implied by #3 in my list.
JSBangs
2009-12-15 19:56:24