Learn Vim / How to Delete All Lines in Vim

How to Delete All Lines in Vim

The answerPress gg then dG — jump to the first line, delete to the last. Or run :%d.

All the ways

KeysWhat it does
ggdGdelete every line
:%dsame, as an ex command
ggVGdsame, via visual mode
:2,$ddelete everything except line 1

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