How do I replace a single character without entering insert mode?
Answer
r{char}
Explanation
The r{char} command replaces the character under the cursor with {char} without ever entering insert mode. It is one of the fastest ways to fix a single-character typo or make a quick substitution.
How it works
renters replace mode for exactly one character{char}is the replacement character you type next- After the replacement, Vim stays in normal mode — no
<Esc>needed
Example
Given the text with the cursor on the a in cat:
The cat sat on the mat
Pressing rc replaces a with c, but that's not useful here. Instead, with the cursor on the c in cat, pressing rb results in:
The bat sat on the mat
Only the single character under the cursor is changed.
Tips
- Use
R(uppercase) to enter replace mode, which lets you overwrite multiple characters continuously until you press<Esc> - Use
5r*to replace the current character and the next 4 characters with*(5 characters total) - Use
r<CR>to replace a character with a newline, effectively splitting the line at the cursor position - The
.command repeatsr{char}— move to another character and press.to replace it with the same character - Unlike
s(which deletes the character and enters insert mode),rkeeps you in normal mode, making it more efficient for single-character fixes - Combine with
f{char}for precise edits:f;r,finds the next semicolon and replaces it with a comma