How do I redo an undone change in Vim?
Answer
<C-r>
Explanation
The <C-r> (Ctrl+r) command redoes the last change that was undone with u. Vim maintains a full undo/redo history, so you can move back and forth through your edits freely.
How it works
uundoes the last change<C-r>redoes the last undone change- You can press
<C-r>repeatedly to redo multiple undone changes
Example
Given the text:
Hello, world!
You delete world! with daw, leaving:
Hello,
Pressing u undoes the deletion, restoring Hello, world!. Pressing <C-r> redoes it, deleting world! again.
Tips
- Vim has an undo tree, not just a linear history — use
:undolistto see the branches - Use
Uto undo all changes on the current line (this counts as its own change) - Use
:earlier 5mto jump to the buffer state from 5 minutes ago - Use
:later 5mto move forward in time - If you accidentally undo too far,
<C-r>will get you back