Vim finds incorrect matching bracket when using %
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?
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.
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.
matchit
plugin would have saved me hours of frustration if I had found it earlier.
There's a small chance pasting this ugly command into your terminal will correctly set up the plugin:
wget http://www.vim.org/scripts/download_script.php?src_id=8196; unzip download_script.php?src_id=8196; echo >> ~/.vimrc; echo -ne "source " >> ~/.vimrc; pwd | tr -d '\n' >> ~/.vimrc; echo -ne "/plugin/matchit.vim" >> ~/.vimrc; rm download_script.php\?src_id\=8196
Then re-source your vimrc:
:source ~/.vimrc
No, I haven't. It might indicate you have missing brackets.
精彩评论