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.
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:
aaa bbb ccc
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.
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:
:redo
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.
Shorter Version of REDO
You can also use [ctrl] + r to redo changes. It is easier and faster.
really helpful post
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!
Helpful VI stuff
been using VI for 10+ years but didn't know about redo... Duh! saved me a bunch of time. Thanks.
Post new comment