“查找下一个”在维姆中
要在 Vim 中向前搜索 cake
,我会输入 /cake
,但当我按回车键时,光标会跳转到第一个匹配项。 是否有类似于“查找下一个”的 Vim 命令?
To search forward in Vim for cake
, I'd type /cake
, but the cursor jumps to the first match when I press return. Is there a Vim command analogous to "find next"?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
下一个是 n,上一个是 N。
如果您使用
?
(例如?cake
)而不是/
进行反向搜索,则情况相反。如果您的系统上安装了它,您应该尝试从终端运行
vimtutor
命令,这将启动基本 Vim 命令的教程。Rob Wells 关于 * 和 # 的建议也非常中肯。
It is n for next and N for previous.
And if you use reverse search with
?
(for example,?cake
) instead of/
, it is the other way round.If it is installed on your system, you should try to run
vimtutor
command from your terminal, which will start a tutorial of the basic Vim commands.Rob Wells advice about * and # is also very pertinent.
恕我直言,Vim 中最有用的快捷键是 * 键。
将光标放在一个单词上并点击 * 键,您将跳转到该单词的下一个实例。
# 键的作用相同,但它跳转到该单词的上一个实例。
这确实节省了时间。
The most useful shortcut in Vim, IMHO, is the * key.
Put the cursor on a word and hit the * key and you will jump to the next instance of that word.
The # key does the same, but it jumps to the previous instance of the word.
It is truly a time saver.
当我开始时,我需要观看演示。
如何在 Vim 中搜索
/
When I was beginning I needed to watch a demo.
How to search in Vim
/
您可能正在寻找 n 键。
You may be looking for the n key.
输入 n 将转到下一场比赛。
Typing n will go to the next match.
正如所讨论的,有多种搜索方式:
另外,使用 N 和 n 导航上一个/下一个。
您还可以通过使用
/
拉出搜索提示,然后使用Cp
/Cn
循环来编辑/调用搜索历史记录。更有用的是q/
,它会将您带到一个可以导航搜索历史记录的窗口。还需要考虑的是非常重要的
'hlsearch'
(输入:hls
启用)。这使得查找模式的多个实例变得更加容易。您甚至可能想让您的匹配项变得更加明亮,例如:但是您可能会因为屏幕上不断出现黄色匹配项而发疯。因此,您会经常发现自己使用
:noh
。这种情况很常见,因此映射是有序的:我很容易记住这个映射为
z
,因为我过去经常键入/zz
(这是一种快速输入) -键入不常见的情况)以清除我的突出显示。但:noh
映射要好得多。As discussed, there are several ways to search:
plus, navigating prev/next with N and n.
You can also edit/recall your search history by pulling up the search prompt with
/
and then cycle withC-p
/C-n
. Even more useful isq/
, which takes you to a window where you can navigate the search history.Also for consideration is the all-important
'hlsearch'
(type:hls
to enable). This makes it much easier to find multiple instances of your pattern. You might even want make your matches extra bright with something like:But then you might go crazy with constant yellow matches all over your screen. So you’ll often find yourself using
:noh
. This is so common that a mapping is in order:I easily remember this one as
z
since I used to constantly type/zz<CR>
(which is a fast-to-type uncommon occurrence) to clear my highlighting. But the:noh
mapping is way better.如果在按“/wordforsearch”之类的内容后按Ctrl + Enter,则可以在当前行中找到单词“wordforsearch”。然后按n进行下一场比赛;按N查看上一场比赛。
If you press Ctrl + Enter after you press something like "/wordforsearch", then you can find the word "wordforsearch" in the current line. Then press n for the next match; press N for previous match.