In the vim text editor, if I want to remove every line in a file that does not contain the word "FALL" in capital letters, I can use
:v/FALL/d
, i.e.,
type the colon key and then v
, which works
like the grep command
grep -v
to select only lines in a file that don't contain a
specified text
string.
The particular text on which you wish vim to searh is preceded and followed by
the slash
delimiter with a d
at the end to specify you wish those lines
not containing the text, e.g., FALL in this case, to be deleted. If I want to
delete only those lines that begin with FALL, I can use
:v/^FALL/d
as the
caret specifies that the text should occur at
the beginning of lines (a dollar sign, $, would indicate I wanted to select
only lines where the text was found at the end of the line). Note:
you can also use :g!/^FALL/d
to achieve the same end —
without the exclamation mark after the global command
, all
lines containing FALL would be deleted, but as the exclamation mark
represents "not", all lines not containing FALL at the beginning of the line
are deleted.