editing
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.
r{char} R (normal mode) Variations
| Keystroke | Effect |
|---|---|
| 3ra | Replace the next 3 characters with 'a' → aaa |
| r<Enter> | Replace character with a newline (splits the line) |
| R | Enter full replace mode (overwrites as you type) |
| gR | Virtual replace mode — treats tabs as spaces so layout doesn't shift |
Examples
rx Replace character under cursor with 'x'
5r- Replace next 5 characters with dashes
Rabc<Esc> Enter replace mode and overwrite the next 3 characters with 'abc'
Gotcha
Backspace in R replace mode UNDOES the replacement (restores original char), not deletes — surprising if you're used to overwrite editors.
Related
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.
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.
Escape
Leaves the current mode and returns to normal mode. Vim is modal — most of the time you want to be in normal mode; if you're not sure what mode you're in, mash Escape.
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.
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.