В Vim: поиск текста, но установка курсора в конце матча?
Есть ли способ поиска шаблона, но при нахождении совпадения курсор в конце шаблона, а не в начале?
Например, /my ENTER поместит курсор в начало "myvariable" ("m").
Я нахожу это часто, было бы удобно, если бы курсор был помещен сразу после конца шаблона поиска (здесь, на 'v'). Это возможно?
2 ответа
Решение
От :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
) приземлиться на v
из myvariable
,
Использование /my/e
, Это поместит курсор в конец шаблона. Если вы используете /my./e
он поместит курсор на первую позицию после шаблона.