Learn Vim / How to Delete a Character in Vim

How to Delete a Character in Vim

The answerMove the cursor onto the character and press x in normal mode.

Try it on a real buffer

Line 2 has a typo: “commannd” has an extra n. Use j to reach line 2, then h j k l to move onto that extra n, and x to delete it.

Vim rewards precise, tiny edits.
Every keystroke is a commannd.
Trust the home row.

Canonical solution: j, move onto the extra n with hjkl, x · target: 29 keystrokes — the fewest that solve it (every keypress counts).

Why it works

h ← · j ↓ · k ↑ · l → — keep your fingers on the home row. x deletes the character under the cursor. Arrow keys work too, but you're here to break that habit.

Variations

KeysWhat it does
xdelete the character under the cursor
Xdelete the character before the cursor
5xdelete five characters
r{char}replace the character instead of deleting it
▶ live vim buffertarget 29 keystrokes
Line 2 has a typo: “commannd” has an extra n. Use j to reach line 2, then h j k l to move onto that extra n, and x to delete it.

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

Sign in free to practice →

Keep going