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. Put the cursor on the first junk line and press 3dd — 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: j 3dd · par: 4 keystrokes (vimgolf rules — 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

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

Practice free — no signup →

Keep going