To undo a change in vi or vim quickly, you can use the undo command (the “u” key) when you are in 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.
To redo a change that was undone, you can either type Control-r or type :redo.
These 2 handy tips are very useful for undoing and redoing changes in vi. Happy editing!