【发布时间】:2014-02-04 13:46:30
【问题描述】:
在 Vim 中,有没有办法搜索与 abc 匹配的行,但后面的行不包含 xyz?所以以下几行将匹配:
The abc is the best
The first three letters are abc
以下内容不匹配:
The abc is the best but xyz is cheaper
The first three letters are abc and the last are xyz
我知道如下语法:
/abc\(xyz\)\@!
但这只会避免匹配abcxyz,而不是如果两者之间有任何东西,例如abc-xyz。使用
/abc.*\(xyz\)\@!
也不起作用,因为该行后面有很多位置 xyz 不匹配。
(我应该注意,在命令行上我会执行类似grep abc <infile | grep -v xyz 的操作,但我想在 Vim 中以交互方式执行上述操作。)
【问题讨论】:
标签: regex vim negative-lookahead