Skip to main content

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.

Core Idea

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 (or Ctrl+[).
  • Ideal for rewriting a run of text without changing its length.

Example — press R, type Amy, then Esc:

name = "Bob"
^^^^^
R"Amy" → name = "Amy"
rR
ScopeOne character (times a count)Continuous until Esc
Leaves you inNormal modeReplace mode
Best forQuick single-character fixesOverwriting a stretch of text

Entering Replace Mode​

KeyModeBehavior
RReplaceOverwrite characters, one for one
gRVirtual ReplaceOverwrite screen cells (tabs expand to spaces)

R vs gR​

  • R replaces real characters. A Tab counts as a single character.
  • gR replaces what you see on screen. A Tab occupies several columns, so gR can 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​

KeyAction
BackspaceRestore the previously replaced character
Ctrl+wDelete (and restore) the previous word
Ctrl+uDelete to start of line
Ctrl+r {reg}Insert register contents
Ctrl+oRun one Normal-mode command, then return
Left / RightMove the cursor
Esc / Ctrl+[Return to Normal mode
Backspace restores, it doesn't just delete

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​

ActionEntersShifts text?
iInsertYes
RReplaceNo
gRVirtual ReplaceNo (screen-wise)
c{motion}Insert (after deleting the motion)No
r{char}One-shot, stays in NormalNo

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​

Practice File

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).

StepKeysWhat happens
1Cursor on the first T of THIS IS THE ORIGINAL TEXT WRITTEN HEREPick the overwrite start point
2RStatus shows -- REPLACE --
3Type that was replaced hereEach keystroke overwrites one character
4EscReturn to Normal mode
5uUndo the overtyping

Each character typed overwrites one existing character; Backspace restores the replaced character, and Esc returns to Normal mode.

In LazyVim​

LazyVim Context

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.

AspectVanilla NeovimLazyVim
Replace modeR, gRSame
One-shot replacer{char}Same
Substitute charsRemapped to flash.nvim — use cl

What's Next​