Find the next occurrence of a variable in vim

倖福魔咒の 提交于 2019-12-20 09:33:16

问题


I would like to know if/how I can make vim look for the next occurrence of a variable. Let's say the variable's name is simply 'n', then /n would give me all occurrences of that letter, which isn't always terribly helpful. I guess I could create a regex to solve the problem, but I wondered whether there was some command/keystroke I simply don't yet know about; and as all my googling has been to no avail I decided to put a question on here.

Thanks a lot for your help!


回答1:


If you have the cursor over the variable in question, you can press * and it will search for the next occurrence or # will search for the previous one.

This is equivalent to typing:

/\<n\>

(\< matches on the start of a word and \> matches on the end of word). The only difference (for reasons I'm not sure of) is that * and # don't pay attention to the 'smartcase' option.

See:

:help *
:help /\<



回答2:


If you press n in command mode it will give you the next match of your search.

More detail:

  • / will start forward search
  • ? will start backward search
  • n will give you the next result in the direction you are searching
  • N will give you the previous result wrt the direction you are searching in


来源:https://stackoverflow.com/questions/4408719/find-the-next-occurrence-of-a-variable-in-vim

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