在搜索一些内容后,如果你按下
//
键,似乎会获得下一个结果。这与n
有何不同?应该如何使用它?//e
匹配什么,还有哪些其他选项可用于//
?//
键,似乎会获得下一个结果。这与n
有何不同?应该如何使用它?//e
匹配什么,还有哪些其他选项可用于//
?搜索命令的格式如下:
/pattern/offset<cr>
如果省略了pattern
部分,则搜索将查找上次搜索的最后一个模式。如果省略偏移量,则不应用偏移量。偏移量基本上是在找到pattern
项目后对光标进行的操作。vi
用户熟悉没有偏移量的变体/pax<cr>
和重复上次搜索/<cr>
,它等同于n
。//<cr>
与/<cr>
相同,它表示重复上次搜索并且不应用偏移量。//e<cr>
表示重复上次搜索并将光标移动到找到的项目的末尾。偏移量为:[num] [num] lines downwards, in column 1
+[num] [num] lines downwards, in column 1
-[num] [num] lines upwards, in column 1
e[+num] [num] characters to the right of the end of the match
e[-num] [num] characters to the left of the end of the match
s[+num] [num] characters to the right of the start of the match
s[-num] [num] characters to the left of the start of the match
b[+num] [num] identical to s[+num] above (mnemonic: begin)
b[-num] [num] identical to s[-num] above (mnemonic: begin)
;{pattern} perform another search, see |//;|
没有指定数字num
时,加减符号默认为1
。
//
的一个好处是可以与s
命令一起使用。因此,如果您最初搜索/Foo
,然后决定用Bar
替换它,您可以这样做而不必重复模式。只需执行:%s//Bar/g
显然,如果模式更加复杂,则此功能更加有用。
//<CR>
的意思是重复上一次搜索,不带偏移量。
//e<CR>
的意思是重复上一次搜索,但会定位到匹配项的结尾。
n
和 /<CR>
相同,它们都使用上一次的模式和偏移量,但是 n
会保留上一次的搜索方向,而 /
总是查找下一个匹配项。
请参阅 :h last-pattern
和 :h search-offset
以获得有关这些命令及其选项的详细说明。
//
是从文件顶部开始搜索吗? - paxdiablo//
将会从你当前所在的位置开始搜索,而 n
将会从上一次匹配的位置开始搜索。顺便说一下,你也可以在替换和全局命令中使用 //
。如果你需要进行较为棘手的匹配,并且想要在正则搜索之前先进行测试,那这个功能就很有用了。 - Alligator