在Vim之后如何删除与模式和行匹配的所有行?

Bor*_*vić 26 regex vim

有一个文字

Title of the text

This line contains a word that is matched by the pattern and it should be deleted.
Next line is supposed to be deleted as well.

Loren ipsum dolorem...

This line contains a word that is matched by the pattern and it should be deleted.
And this one should be deleted

The end of the article
Run Code Online (Sandbox Code Playgroud)

如何删除与第一行匹配的每一对行,例如"此行包含一个单词..."以及该行之后的行.结果将是:

Title of the text

Loren ipsum dolorem...

The end of the article
Run Code Online (Sandbox Code Playgroud)

FDi*_*off 45

您可以使用

:g/word/normal 2dd
Run Code Online (Sandbox Code Playgroud)

这将查找word的所有实例,然后在其后执行命令.在这种情况下,它2dd以正常模式执行


Pav*_*sov 21

使用:g[lobal]一个d[elete]命令与,+1要删除的匹配线和下:

:g/word/,+1d
Run Code Online (Sandbox Code Playgroud)


rom*_*inl 5

您可以使用以下:g[lobal]命令:

:g/This line/norm 3dd
Run Code Online (Sandbox Code Playgroud)