How to delete a specific line that happened many times in a file in vim

I want to delete the line: This is an examplethat happens several times in the file. How should I do it.

Thanks Alisha

+3
source share
4 answers

You can do:

:g/This is an example/d
+16
source
:%s/This is an example\n//gc

% indicates all lines of a file
s indicates pattern to be searched.
g for global replacement
c for confirmation on each replace
+3
source

If you want to delete lines containing only exact matches, you can:

:g/^This is an example$/d
+3
source

You can do this using an external command:

:%!grep -v "This is an example"

Filters the entire file with this command. The command grep -vselects all lines of the file that do not match the given regular expression.

+2
source

All Articles