本文翻译自:“Find next” in vim
To search forward in vim for cake
, I'd type /cake
, but the cursor jumps to the first match when I press return. 要在vim中向前搜索cake
,我会输入/cake
,但是当我按下返回时光标跳到第一个匹配。 Is there a vim command analogous to "find next"? 是否有类似于“查找下一个”的vim命令?
#1楼
参考:https://stackoom.com/question/Riwg/在vim中-找到下一个
#2楼
When I was beginning I needed to watch a demo 当我开始时,我需要观看演示
How to search in VIM 如何在VIM中搜索
- type
/
类型/
- type search term eg "var" 类型搜索词例如“var”
- press enter 按 回车 键
- for next instance press n (for previous N ) 对于下一个实例按n (对于前一个 N )
#3楼
As discussed, there are several ways to search: 如上所述,有几种搜索方式:
/pattern
?pattern
* (and g*, which I sometimes use in macros)
# (and g#)
plus, navigating prev/next with N and n . 另外,使用N和n导航prev / next。
You can also edit/recall your search history by pulling up the search prompt with /
and then cycle with Cp
/ Cn
. 您还可以通过使用/
提取搜索提示来编辑/调用搜索历史记录,然后使用Cp
/ Cn
循环。 Even more useful is q/
, which takes you to a window where you can navigate the search history. 更有用的是q/
,它会将您带到一个可以浏览搜索历史的窗口。
Also for consideration is the all-important 'hlsearch'
(type :hls
to enable). 另外需要考虑的是最重要的'hlsearch'
(类型: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: 您甚至可能希望通过以下方式使您的比赛变得更加明亮:
hi Search ctermfg=yellow ctermbg=red guifg=...
But then you might go crazy with constant yellow matches all over your screen. 但是你可能会因为整个屏幕上的黄色火柴而疯狂。 So you'll often find yourself using :noh
. 所以你经常会发现自己在使用:noh
。 This is so common that a mapping is in order: 这是如此常见以至于映射是有序的:
nmap <leader>z :noh<CR>
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. 我很容易记住这个作为z
因为我曾经不断地输入/zz<CR>
(这是一种快速到类型的罕见事件)来清除我的突出显示。 But the :noh
mapping is way better. 但是:noh
映射更好。
#4楼
如果在按下“/ wordforsearch”之后按ctrl + enter,则可以在当前行中找到单词“wordforsearch”。然后按n进行下一个匹配;按N进行常规匹配。
#5楼
It is n for next and N for previous. 下一个是n ,之前是N.
And if you use reverse search with ?
如果你使用反向搜索?
(eg ?cake
) instead of /
, it is the other way round. (例如?cake
)代替/
,反之亦然。
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. 如果它安装在您的系统上,您应该尝试从终端运行vimtutor
命令,这将启动基本Vim命令的教程。
Rob Wells advice about *
and #
is also very pertinent. Rob Wells关于*
和#
建议也非常贴切。
#6楼
输入n将进入下一场比赛。