Vim redo and undo

Dayne Dayne (57)
Total time: 5 minutes 

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.


Command Description
u undo
ctrl-r redo

And for undo branches

Command Description
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
Posted in these interests:
h/vim23 guides

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.

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

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

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.