Learn Vim / How to Delete Multiple Lines in Vim

How to Delete Multiple Lines in Vim

The answerPress 3dd to delete three lines starting at the cursor. Any count works: 10dd, 100dd.

Try it on a real buffer

Three junk lines sit together. You're on the first one — press 3dd to delete all three (a count multiplies any command).

keep: the mission briefing
junk: shredder food
junk: more shredder food
junk: even more shredder food
keep: the victory speech

Canonical solution: 3dd · target: 3 keystrokes — the fewest that solve it (every keypress counts).

Why it works

Counts work everywhere: 3dd deletes three lines, 5x deletes five characters, 2yy yanks two lines, 4w hops four words. Think in multiples.

Variations

KeysWhat it does
3dddelete 3 lines
djdelete this line + the next
:2,5ddelete lines 2–5 by number
VG dvisual-select to end of file, delete
:g/pattern/ddelete every line matching a pattern
▶ live vim buffertarget 3 keystrokes
Three junk lines sit together. You're on the first one — press 3dd to delete all three (a count multiplies any command).

Reading about keystrokes doesn't build keystrokes. Try this in a real vim buffer right now — the “Triple threat” mission takes about a minute.

Sign in free to practice →

Keep going