Vim redo and undo

Dayne Dayne (57)
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. You may also want to check out our guide on how to get started with Vim.


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.

Dayne Dayne (57)

You probably already know how to use vim's basic undo and redo features. For a quick refresher, read this short tutorial on how to use vim redo and undo.