34

有一段文字

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

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

Title of the text

Loren ipsum dolorem...

The end of the article
4

5 回答 5

60

您可以使用

:g/word/normal 2dd

这会找到 word 的所有实例,然后执行它之后的命令。在这种情况下,它2dd以正常模式执行

于 2013-04-25T19:27:35.613 回答
29

:g[lobal]与具有范围的d[elete]命令一起使用以,+1删除匹配的行和下一行:

:g/word/,+1d
于 2013-04-25T19:27:33.037 回答
6

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

:g/This line/norm 3dd
于 2013-04-25T19:27:58.280 回答
3

另一种方式:g

:g/word/norm dj
于 2013-04-25T20:48:00.873 回答
2

你可能想试试这个:

:g/your pattern go here/d
于 2015-03-20T04:44:44.463 回答