在Vim中包含一个或多个关键字的行的操作

Jam*_*Box 2 vim

如果我希望在包含某个关键字的所有行上运行相同的命令,我可以使用global命令,或者对不包含该关键字的行使用vglobal命令.

例如,如果我有一个包含以下内容的文本文件:

hello world
testing with foo
another test with bar in it
another foo line
last test line
Run Code Online (Sandbox Code Playgroud)

:g/foo/d删除包含foo给我这个词的所有行:

hello world
another test with bar in it
last test line
Run Code Online (Sandbox Code Playgroud)

我可以使用此命令操作包含多个单词中的一个或多个的行; OR语句的某些内容.例如,删除包含单词fooOR的所有行bar,给我:

hello world
last test line
Run Code Online (Sandbox Code Playgroud)

谢谢

FDi*_*off 6

全局命令将正则表达式作为输入.所以你只需要使用alternation(\|)or.

:g/foo\|bar/d
Run Code Online (Sandbox Code Playgroud)

会删除包含"foo"或"bar"的行.