开发者

Vim finds incorrect matching bracket when using %

开发者 https://www.devze.com 2022-12-13 20:37 出处:网络
I am trying to learn VIM, buy I noticed when I try using the % command to go to a matching bracket, VIMsometimes finds the correct开发者_如何转开发 matching bracket and is sometimes way off. Has anyon

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:

  1. You have an actual syntax error with a mismatched paren or curly brace somewhere.
  2. You have a value in cpoptions that prevents semi-intelligent brace matching. Look up :help cpoptions and :help %.
  3. 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消