← All lessons

7. Undo And Redo

Step 1 of 5

Undo

Mistakes are part of life. Fortunately, Vim has great support for undoing them. Only in text editing though. Vim can’t help you otherwise.

Vim remembers changes and you can use the undo command to revert the text to how it was before. If you make a change you’d like to undo, hit the u key in normal mode. You can repeatedly press the u key as many times as you need.

The u command also accepts a count, so you can do something like 10u to walk back 10 steps in your undo history. You can do this with a really high count — like 1000u — to revert the document back to the way that it was before you made any edits.

This is a really good one to remember! Because Vim is so powerful, even just a few accidental keystrokes can modify the document in strange ways. At some point during your Vim journey, I am sure that you’ll type something by mistake and it’ll do something you don’t expect. Having undo is a great safety net.

Try this in the editor. Do whatever you want! Type some text, delete something, change something — anything goes. You can always use the u command to walk back to the state you were in before.

Loading editor…