在 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中交互式地执行上述操作。)
<infile
而不是只用infile
? - Good Pen