How to undo and redo changes in vi/vim

vi/vim editor FAQ: How do I undo and redo changes in the vi and vim editor?

Here are a couple of quick examples of how to undo and redo (“re-do”) recent changes in your vi/vim editor sessions.

vim undo (how to undo a change in vi/vim)

You “undo” changes in vi and vim with the undo command, which is the u key when you are in vim command mode. For instance, if you start with this text in your editor:


Then delete the second line with the vi dd command, you can then undo this change by typing the letter u while still in command mode. This undo command works with other changes as well, including inserts, deletes, search and replace functions, etc.

vim redo (how to redo something you just un-did)

Update: As noted in the Comments section below, the best way to redo a vim command is to use the [Ctrl][r] keystroke.

Another approach to redo a command in vi/vim is to enter the “redo” command in last-line mode, like this:


For instance, if you wanted to again delete that second line, you could type this command to re-do that change. But again, since learning about it, the [Ctrl][r] keystroke is a much faster way to undo a change in vim.


thank you soooo much!
I was about to switch to nano for good till your post saved me!!!
than you again for your handy hints!


been using VI for 10+ years but didn't know about redo... Duh! saved me a bunch of time. Thanks.

Add new comment

The content of this field is kept private and will not be shown publicly.

Anonymous format

  • Allowed HTML tags: <em> <strong> <cite> <code> <ul type> <ol start type> <li> <pre>
  • Lines and paragraphs break automatically.
By submitting this form, you accept the Mollom privacy policy.