Replace Mode
Replace mode overwrites existing characters as you type — the way the Insert key works in a word processor. Nothing to the right is pushed forward; the new text lands on top of the old text.
Insert mode inserts (shifts text right). Replace mode overwrites (replaces in place). Reach for Replace when the character count must stay exactly the same.
The Difference Between r and R
The short version: r replaces a character once, while R enters a continuous Replace mode.
1. r — Single-character Replace
- Replaces the character under your cursor.
- Returns to Normal mode immediately.
- Ideal for quick, small corrections.
Example — press r9:
age = 30
^
r9 → age = 90
2. R — Continuous Replace Mode
- Overwrites characters as you keep typing.
- Stays in Replace mode until you press
Esc(orCtrl+[). - Ideal for rewriting a run of text without changing its length.
Example — press R, type Amy, then Esc:
name = "Bob"
^^^^^
R"Amy" → name = "Amy"
r | R | |
|---|---|---|
| Scope | One character (times a count) | Continuous until Esc |
| Leaves you in | Normal mode | Replace mode |
| Best for | Quick single-character fixes | Overwriting a stretch of text |
Entering Replace Mode
| Key | Mode | Behavior |
|---|---|---|
R | Replace | Overwrite characters, one for one |
gR | Virtual Replace | Overwrite screen cells (tabs expand to spaces) |
R vs gR
Rreplaces real characters. ATabcounts as a single character.gRreplaces what you see on screen. ATaboccupies several columns, sogRcan overwrite many columns with few keystrokes and never shifts the text.
Line: <Tab>abc (cursor on the Tab)
R then type XYZ → XYZc (the Tab is overwritten as one character)
gR then type XYZ → XYZ<Tab>abc (the Tab survives; XYZ only filled 3 of its columns)
Read the ruler — the ^ marks the characters overwritten. R keeps overwriting for as long as you stay in the mode, and the length never changes:
name = "Bob"
^^^^^
R"Amy" → name = "Amy" (5 chars in, 5 chars out)
Replacing Multiple Characters with r
r also accepts a count to replace several characters in one shot:
r{char} → replace the character under the cursor
3r{char} → replace the next 3 characters
Read the ruler — r is one-shot and touches only what its count covers:
age = 300
^^^
3r9 → age = 999 (the next 3 chars, one for one)
:help r — r is a one-shot; it does not leave you in a persistent mode.
Editing in Replace Mode
| Key | Action |
|---|---|
Backspace | Restore the previously replaced character |
Ctrl+w | Delete (and restore) the previous word |
Ctrl+u | Delete to start of line |
Ctrl+r {reg} | Insert register contents |
Ctrl+o | Run one Normal-mode command, then return |
Left / Right | Move the cursor |
Esc / Ctrl+[ | Return to Normal mode |
In Replace mode, Backspace (and Ctrl+w) put the original characters back. So R → type a few characters → Backspace is a safe way to undo overtyping without leaving the mode.
Replace vs Insert vs Change
| Action | Enters | Shifts text? |
|---|---|---|
i | Insert | Yes |
R | Replace | No |
gR | Virtual Replace | No (screen-wise) |
c{motion} | Insert (after deleting the motion) | No |
r{char} | One-shot, stays in Normal | No |
Visual Mode Replace
In Visual mode, r replaces every selected character with a single character — perfect for masking:
v{motion} r x → replace the whole selection with 'x'
Vjjrx → replace three full lines with 'x'
Ctrl+v ... rx → blank out a column
Common Use Cases
- Editing fixed-width / aligned columns without breaking the layout
- Changing digits in a number that must keep the same length
- Patching a word with a same-length replacement
- Masking sensitive values (
v...rx) - Editing fixed-format data such as CSV columns
Repeat and Undo
. → repeat the last Replace-mode change
u → undo
Ctrl+r → redo
Practice
Open the step-by-step drills: practice-folder/nvim/02-modal-editing/modes-practice.md (Drill 7)
(also available via the shell alias n02-modes).
| Step | Keys | What happens |
|---|---|---|
| 1 | Cursor on the first T of THIS IS THE ORIGINAL TEXT WRITTEN HERE | Pick the overwrite start point |
| 2 | R | Status shows -- REPLACE -- |
| 3 | Type that was replaced here | Each keystroke overwrites one character |
| 4 | Esc | Return to Normal mode |
| 5 | u | Undo the overtyping |
Each character typed overwrites one existing character; Backspace restores the replaced character, and Esc returns to Normal mode.
In LazyVim
Replace mode works exactly as in vanilla Neovim. LazyVim does not remap R or gR. Note that LazyVim remaps s to flash.nvim, so to "replace a character and insert" use cl or xi rather than s.
| Aspect | Vanilla Neovim | LazyVim |
|---|---|---|
| Replace mode | R, gR | Same |
| One-shot replace | r{char} | Same |
| Substitute char | s | Remapped to flash.nvim — use cl |