简体   繁体   English

在 vim 中查找变量的下一次出现

[英]Find the next occurrence of a variable in vim

I would like to know if/how I can make vim look for the next occurrence of a variable.我想知道是否/如何让 vim 查找下一次出现的变量。 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.假设变量的名称只是 'n',然后/n会给我所有出现的那个字母,这并不总是非常有帮助。 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!非常感谢你的帮助!

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.唯一的区别(出于我不确定的原因)是*#不注意'smartcase'选项。

See:见:

:help *
:help /\<

If you press n in command mode it will give you the next match of your search.如果您在命令模式下按n ,它将为您提供下一个搜索匹配项。

More detail:更多细节:

  • / will start forward search /将开始向前搜索
  • ? will start backward search将开始向后搜索
  • n will give you the next result in the direction you are searching n在您搜索的方向上为您提供下一个结果
  • N will give you the previous result wrt the direction you are searching in N在您搜索的方向上为您提供先前的结果

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM