Step 1 of 5

7. Undo And Redo

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.

Work through the checklist below. The change can be anything — type some text, delete something, change something — and u will walk you back to the state you were in before.

  1. Enter insert mode The mode indicator will flip to INSERT — press i.
  2. Make a change, then return to normal mode Type anything you like, then hit Escape.
  3. Undo the change Watch your edit disappear — press u.
Enter insert mode The mode indicator will flip to INSERT — press i.

Next: Make a change, then return to normal mode

Loading editor…