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
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.