Vim redo and undo

Learn how to undo and redo changes using vim. If you are brand new to vim, learn more about the basics in this intro to vim guide.

TL;DR

CommandDescription
uundo
ctrl-rredo

And for undo branches

CommandDescription
g-move back 1 chronological changes
g+move forward 1 chronological changes
:earlier <num>move back <num> chronological changes
:later <num>move forward <num> chronological changes
1

Vim keeps track of an "undo stack", a linear history of all the changes you've made. Adding something in insert mode adds 1 item to the undo stack. Using u or ctrl-r traverses up and down the stack until you being inserting something else.

2

In command mode, press u to undo the most recent change. Easy!

3

To redo the most recently undone command, press ctrl-r.

4

Advanced users will find undo branches useful. Vim actually keeps track of every change you've ever made. Vim uses a tree structure that can be navigated using g- and g+ or :earlier and later. Further reading in this guide on vim undo branches.