Learn Vim / How to Undo and Redo in Vim

How to Undo and Redo in Vim

The answerPress u to undo and Ctrl-r to redo, in normal mode.

Try it on a real buffer

This poem is perfect. Break it however you like (x, dw, dd — go wild), then press u repeatedly until every change is undone.

roses are red
violets are blue
undo is a superpower
and now so are you

Canonical solution: dd (or any damage), then u until restored · par: 2 keystrokes (vimgolf rules — every keypress counts).

Why it works

u undoes one change at a time; Ctrl-r redoes. Knowing that u always has your back is what makes the rest of vim feel safe to experiment with.

Variations

KeysWhat it does
uundo the last change
5uundo five changes
Ctrl-rredo
Uundo all changes on the current line

Reading about keystrokes doesn't build keystrokes. Try this in a real vim buffer right now — the “The safety net” mission takes about a minute.

Practice free — no signup →

Keep going