搜索命令`//`在Vim中如何工作? [英] How does the search command `//` work in Vim?

查看:121
本文介绍了搜索命令`//`在Vim中如何工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

搜索某些内容后,如果单击//,则似乎会得到下一个结果.与n有何不同?您应该如何使用它? //e匹配什么?//还有什么其他选项?

After searching for something, if you hit //, you seem to get the next result. How is this different from n? How should you use it? What does //e match, and what other options are there for //?

推荐答案

搜索命令具有以下格式:

The search command is of the following format:

/pattern/offset<cr>

如果省略了pattern部分,则搜索将查找所搜索的最后一个模式.如果忽略了偏移量,则不会应用任何偏移量.基本上,偏移是找到pattern项后要对光标执行的操作.

If the pattern part is left out, the search looks for the last pattern that was searched for. If the offset is left out, no offset is applied. The offset is basically what to do to the cursor once you've found your pattern item.

大多数vi用户对不带偏移量的变体/pax<cr>和重复的最后一次搜索/<cr>(与n等效)很熟悉.

Most vi users are familiar with the variation without an offset, /pax<cr> and the repeat last search, /<cr>, which is equivalent to n.

在您的特定示例中,//<cr>/<cr>相同,表示重复上一次搜索并且不应用偏移.

In your specific examples, //<cr> is the same as /<cr> and it means repeat the last search and apply no offset.

另一方面,//e<cr>表示重复上一次搜索并将光标移动到找到的项目的末尾.偏移量是:

On the other hand, //e<cr> means to repeat the last search and move the cursor to the end of the found item. The offsets are:

[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.

这篇关于搜索命令`//`在Vim中如何工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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