editing
x
Deletes the character under the cursor — Vim's equivalent of the Delete key. It's a cut, so the character lands in the unnamed register.
x (normal mode) Variations
| Keystroke | Effect |
|---|---|
| X | Delete character BEFORE the cursor (like Backspace) |
| 5x | Delete 5 characters starting at cursor |
| xp | Classic typo-swap: delete this char and paste it after (swaps with next char) |
Examples
x Delete character under cursor
3x Delete 3 characters to the right
Xx Delete the char before AND the char under the cursor
Gotcha
x won't cross line boundaries — hitting x on an empty line does nothing. On the last char of a line the cursor moves left after deletion.
Related
dd
Deletes the current line (and stores it in the unnamed register, so you can paste it back with p). The bread-and-butter 'get rid of this line' command.
r / R
r replaces the single character under the cursor with the next key you press — no need to enter insert mode. Capital R enters REPLACE mode, where every character you type overwrites the one under the cursor until Escape.
u / Ctrl-R
u undoes the last change; Ctrl-R redoes it. Vim has a full undo TREE (see :undolist and g-/g+) but for day-to-day work these two keys are enough.
i / a / o / O
The four ways to enter insert mode: i inserts BEFORE the cursor, a inserts AFTER it, o opens a new line BELOW and enters insert mode, O opens a new line ABOVE. Choosing the right one saves a motion or two before you start typing.
yy
'Yank' (copy) the current line into the unnamed register — Vim's word for copy. Combine with p/P to duplicate lines without touching your system clipboard.