linematches /DEBUG/resultkeep thisnokeptDEBUG noiseyesdeletedkeep thatnokeptDEBUG moreyesdeleted:g/DEBUG/d — test every line, act on the matches.
:g visits every line once, tests it against the pattern, and runs the command only where it matched. Swap the d for normal A; and the same sweep appends instead of deletes.
Vim The global command: :g
advanced » Delete every line containing "DEBUG".
goal
keep this
keep that
scratch.txt
1 keep this
2 DEBUG noise
3 keep that
4 DEBUG more
-- NORMAL -- 1,1
keys
your keystrokes appear here as you press them
NORMAL ~/learn/vim-motions · 1/1 · :g//d real vim keys trail · always esc in-editor

Best on a keyboard

“The global command: :g” is a hands-on typing drill — it needs a physical keyboard. Open it on a laptop or desktop to play. You can still browse and read everything here on your phone.

Back to course →
NORMAL ~/memra/learn/vim-motions/the-global-command utf-8 LF