在 Vim 中:正在搜索文本但将光标放在匹配项的末尾?
In Vim: Searching for text but putting the cursor at the end of the match?
有没有一种方法可以搜索模式,但在匹配时将光标放在模式的末尾而不是开头?
例如,/my ENTER 会将光标置于 'myvariable' ('m') 的开头。
我经常发现,如果光标紧跟在搜索模式结束之后(此处,在 'v' 上),会很方便。这可能吗?
使用/my/e
。这会将光标置于模式的末尾。如果您使用 /my./e
,它将把光标放在模式之后的第一个位置。
从 :help /
你可以看到 /{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
)降落在 myvariable
的 v
。
有没有一种方法可以搜索模式,但在匹配时将光标放在模式的末尾而不是开头?
例如,/my ENTER 会将光标置于 'myvariable' ('m') 的开头。
我经常发现,如果光标紧跟在搜索模式结束之后(此处,在 'v' 上),会很方便。这可能吗?
使用/my/e
。这会将光标置于模式的末尾。如果您使用 /my./e
,它将把光标放在模式之后的第一个位置。
从 :help /
你可以看到 /{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
)降落在 myvariable
的 v
。