Comment supprimer toutes les lignes correspondant à un motif et une ligne après dans Vim?

Il y a un texte

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

Comment supprimer chaque paire de lignes correspondant à la première ligne, par exemple ' cette ligne contient un mot..."et la ligne après que l'un. Le résultat serait:

Title of the text

Loren ipsum dolorem...

The end of the article
26
demandé sur Brian Tompsett - 汤莱恩 2013-04-25 23:21:58

5 réponses

Vous pouvez utiliser

:g/word/normal 2dd

Ceci trouve toutes les instances de word, puis exécute la commande après. Dans ce cas, il exécute 2dd en mode normal

43
répondu FDinoff 2013-04-25 19:27:35

Utilisez :g[lobal] avec une commande d[elete] avec une plage ,+1 pour supprimer la ligne correspondante et la suivante:

:g/word/,+1d
20
répondu Pavel Anossov 2013-04-25 19:27:33

Vous pouvez utiliser la commande :g[lobal]:

:g/This line/norm 3dd
4
répondu romainl 2013-04-25 19:27:58

Une autre façon avec: g

:g/word/norm dj
2
répondu Kent 2013-04-25 20:48:00

, Vous pouvez essayer ceci:

:g/your pattern go here/d
-2
répondu Thanh Nguyen 2015-03-20 10:41:52