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:
cpoptions
that prevents semi-intelligent brace matching. Look up :help cpoptions
and :help %
.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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With