Learn Vim / How to Delete to the End of the Line in Vim

How to Delete to the End of the Line in Vim

The answerPress D — it deletes from the cursor to the end of the line. Pair with f to land exactly where the deleting should start.

Try it on a real buffer

On line 1, jump to the # with f#, then press D to delete from the cursor to the end of the line.

total = price * quantity  # TODO delete this trailing comment
tax = total * 0.2

Canonical solution: f# D · par: 3 keystrokes (vimgolf rules — every keypress counts).

Why it works

D is shorthand for d$ — delete to end of line. Its cousin C changes to end of line. Pair them with f/t jumps for precise strikes.

Variations

KeysWhat it does
Ddelete to end of line
Csame, then enter insert mode
d0delete to the beginning of the line
f# Djump to the # character, delete from there

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

Practice free — no signup →

Keep going