使用vim搜索模式,如何设置vim将光标移动到另一个指定字符左边两个空格的字符?例如,在' ='之前的字符有两个空格。登录。
答案 0 :(得分:2)
您可以将偏移传递给搜索模式
/{pattern}/{offset}
对于这种情况(=之前的两个字符),你想要
/=/b-2
匹配=符号,然后在匹配开始前将光标放两个字符(/=/s-2
s for start也可以使用)
查看:h search-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).
答案 1 :(得分:1)
如果您处于正常模式,则可以使用此模式:
/..=/
。指任何字符
请注意,以下情况不包含在模式中,因为“ = ”之前没有足够的字符。
| =
| =
。(点)我指的是任何字符,并且 | 是起始行的限制。