[英]How to delete all lines matching a pattern and a line after in Vim?
There's a text 有一个文字
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
How to delete every pair of lines matching the first line, eg 'This line contains a word...' and the line after that one. 如何删除与第一行匹配的每一对行,例如“此行包含一个单词...”以及该行之后的行。 Result would be: 结果将是:
Title of the text
Loren ipsum dolorem...
The end of the article
You can use 您可以使用
:g/word/normal 2dd
This finds all instances of word and then executes the command after it. 这将查找word的所有实例,然后在其后执行命令。 In this case it executes 2dd
in normal mode 在这种情况下,它在正常模式下执行2dd
Use :g[lobal]
with a d[elete]
command with a ,+1
range to delete matched line and the next: 使用:g[lobal]
使用带有,+1
范围的d[elete]
命令删除匹配的行和下一行:
:g/word/,+1d
您可以使用:g[lobal]
命令:
:g/This line/norm 3dd
另一种方式:g
:g/word/norm dj
你可能想试试这个:
:g/your pattern go here/d
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.