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:
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.
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
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.
There’s just one person behind this website; if this article was helpful (or interesting), I’d appreciate it if you’d share it. Thanks, Al.
You can also use [ctrl] + r to redo changes. It is easier and faster.
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.