在Vim中:搜索文本但将光标放在匹配的末尾?

时间:2018-06-13 14:11:18

标签: vim neovim

是否有搜索模式的方法,但是当匹配时,将光标放在模式的末尾而不是开头?

例如,/我的ENTER会将光标放在' myvariable'的开头。 ('米&#39)。

我经常发现,如果在搜索模式结束后立即放置光标(此处,在' v'上)会很方便。这可能吗?

2 个答案:

答案 0 :(得分:5)

/{pattern}/{offset}<CR>,您可以看到:help offset模式 来自 *search-offset* *{offset}* These commands search for the specified pattern. With "/" and "?" an additional offset may be given. There are two types of offsets: line offsets and character offsets. The offset gives the cursor position relative to the found match: [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 ## This is the one you want 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 |//;| If a '-' or '+' is given but [num] is omitted, a count of one will be used. When including an offset with 'e', the search becomes inclusive (the character the cursor lands on is included in operations).

/my/e+

因此,在您的情况下,使用/my/e+1(或v)登陆myvariable {{1}}。

答案 1 :(得分:3)

使用/my/e。这会将光标放在模式的末尾。如果使用/my./e,它会将光标放在模式后面的第一个位置。