如何在VIM中跳转到下一个匹配项之后?

5
我正在处理一个文件,需要进行大量的编辑。我需要编辑的内容前面是固定的文本,但需要编辑的内容不同。目前我正在使用/my_constant_textn 来跳转到需要编辑的行。但是这样使用n时,我仍然需要将光标向前移动以到达我想要编辑的位置。我认为一定有一种方法可以使光标直接跳到匹配文本的后面,但是我找不到合适的方法。
如果有帮助的话,我正在处理的文件看起来像下面这两行,只是值不同而已,重复出现了很多次。
INSERT INTO TABLE (ID, NAME, VALUE) VALUES ('1','foo','all sorts of random stuff')
INSERT INTO TABLE (ID, NAME, VALUE) VALUES ('2','bar','some other random stuff')

我希望能够跳到'foo','(即my_constant_text)之后的光标位置。
3个回答

10

使用/constant_text/e跳转到常量文本的末尾,或者/constant_text/e+1跳转至其之后。


1
显然这被称为搜索偏移量,:help offset - Brandon Wigfield
你可以使用 ://e+3、://e-1、://b+1 等不同的方式。 - sehe

2

事情可以更加多样化 http://vimdoc.sourceforge.net/htmldoc/pattern.html#{offset}

[...]  With "/" and "?" an
additional offset may be given.  There are two types of offsets: line offsets
and character offsets.  {the character offsets are not in Vi}

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
    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 |//;|

0
正如 Jan 所说,使用 '/e' 修饰符。如果情况比单纯的搜索字符串更复杂,总有宏可用。
qanf,q

将宏nf(这里指的是复杂的代码,而不仅仅是nf)存储在名为a的宏中,然后

@a

调用它。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接