在 vim 中查找变量的下一次出现 [英] Find the next occurrence of a variable in vim

查看:70
本文介绍了在 vim 中查找变量的下一次出现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否/如何让 vim 查找下一次出现的变量.假设变量的名称只是 'n',然后 /n 会给我所有出现的那个字母,这并不总是非常有用.我想我可以创建一个正则表达式来解决这个问题,但我想知道是否有一些我还不知道的命令/击键;由于我所有的谷歌搜索都无济于事,我决定在这里提出一个问题.

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.

非常感谢您的帮助!

推荐答案

如果您将光标悬停在有问题的变量上,您可以按 * ,它会搜索下一个出现或 # 将搜索上一个.

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.

这相当于输入:

/\<n\>

(\< 匹配单词的开头,\> 匹配单词的结尾).唯一的区别(出于我不确定的原因)是 *# 不注意 'smartcase' 选项.

(\< 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.

见:

:help *
:help /\<

这篇关于在 vim 中查找变量的下一次出现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆