Regex Vim:将光标移动到字符前面两个空格处
使用vim搜索模式,如何设置vim以将光标移动到另一个指定字符左侧两个空格的字符?例如,字符在“=”符号前两个空格。如果处于正常模式,则可以使用此模式:Regex Vim:将光标移动到字符前面两个空格处,regex,vim,Regex,Vim,使用vim搜索模式,如何设置vim以将光标移动到另一个指定字符左侧两个空格的字符?例如,字符在“=”符号前两个空格。如果处于正常模式,则可以使用此模式: /..=/ 。指任何字符 请记住,模式中不包括以下情况,因为“=”之前没有足够的字符 |= |= 用(点)我指的是任何字符,用|指的是起始线的限制。可以将偏移量传递给搜索模式 /{pattern}/{offset} 对于这种情况(在=)之前有两个字符),您需要 /=/b-2 将匹配=符号,然后将光标放在匹配开始前两个字符(/=/s-2s表
/..=/
。指任何字符
请记住,模式中不包括以下情况,因为“=”之前没有足够的字符
|=
|=
用(点)我指的是任何字符,用|指的是起始线的限制。可以将偏移量传递给搜索模式
/{pattern}/{offset}
对于这种情况(在=)之前有两个字符),您需要
/=/b-2
将匹配=符号,然后将光标放在匹配开始前两个字符(/=/s-2
s表示开始也可以)
查看:h搜索偏移量
(复制如下)
搜索偏移量{offset}
这些命令搜索指定的模式。带有“/”和“?”的
可以给出额外的偏移量。偏移有两种类型:线偏移
和字符偏移。{字符偏移量不在Vi}
偏移量给出了光标相对于找到的匹配项的位置:
第1列中向下[num][num]行
+第1列中向下[num][num]行
-[num][num]行向上,在第1列中
匹配结束右侧的e[+num][num]个字符
匹配结束左侧的e[-num][num]个字符
匹配开始右侧的s[+num][num]个字符
匹配开始左侧的s[-num][num]个字符
b[+num][num]与上面的s[+num]相同(助记符:开始)
b[-num][num]与上面的s[-num]相同(助记符:begin)
;{pattern}执行另一个搜索,请参见/;
如果给定了“-”或“+”,但省略了[num],则将使用一个计数。
当包含带有“e”的偏移量时,搜索将变为包含(以下为
光标落在的字符包含在操作中)。
t=h
?谢谢你,哈奇,你知道有没有办法用vim中的/search特性来完成我的要求?这就是我希望得到的答案。我不知道,除了搜索后的hh
或2h
。干杯。如果重要的话,可以通过帮助页面轻松找到这些信息<代码>:help/将您带到帮助进行搜索。第二段说你可以传递一个偏移量。然后,如果在{offset}
符号上单击
,它会将您带到:帮助搜索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 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 //;
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).