Learn Vim / How to Delete a Line in Vim

How to Delete a Line in Vim

The answerPress dd in normal mode. The cursor can be anywhere on the line.

Try it on a real buffer

One line doesn't belong on this list. Move onto it and delete the entire line with dd.

Shopping list:
- eggs
- flour
DELETE ME I should not be here
- butter
- sugar

Canonical solution: 3j, then dd · par: 4 keystrokes (vimgolf rules — every keypress counts).

Why it works

dd deletes the whole current line, wherever the cursor sits on it. (It also copies the line into a register — that will matter later.)

Variations

KeysWhat it does
dddelete the current line
3dddelete three lines
djdelete this line and the one below
:5ddelete line 5 without moving there
Ddelete from the cursor to the end of the line (keep the line)

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

Practice free — no signup →

Keep going