Vim and Ruby - matching “do”s and “end”s?

為{幸葍}努か 提交于 2019-12-22 02:22:14

问题


I'm sure we're all familiar with the "unexpected kEnd" problem. They are always (to me) a lot of trouble to track down, because Vim doesn't match "do"s and "end"s. (And, obviously, other elements that end with "end", like "if")

Is there a way to configure Vim to show these matches to help make debugging easier?


回答1:


If you are using a recent vim (I'm using 7.4), the built-in matchit macro works well with ruby code.

Simply enable it by adding the following to your .vimrc

runtime macros/matchit.vim

Hit % to match do/end combos and many others in ruby files.




回答2:


I use this macro and then add this to my vimrc to enable it:

" % to bounce from do to end etc.
runtime! macros/matchit.vim

When I want to find the matching end for a do, I cursor over the do and hit %.




回答3:


"endwise" is a pretty nice vim extension that adds them automatically, which I found greatly reduces the amount of missing ends. etc:

http://www.vim.org/scripts/script.php?script_id=2386




回答4:


I use this matchit clone, that can be installed easily with vundle.



来源:https://stackoverflow.com/questions/8067876/vim-and-ruby-matching-dos-and-ends

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!