Quite obviously, there are people who do not know about the undo and redo functions when editing in vim. That’s a pity, because it is really helpful. I frequently use this when testing the effects of some small changes in configuration files or scripts; just leave the editor open in one window, make the changes, save the file and run the script or program in another terminal window to check the outcome of the changes. If it does not work as you intended and you want to go back, simply use the undo command as often as necessary to go back to the point where you want to be. This way you can be sure you really undo exactly the changes you made and do not inadvertently introduce a mistake.
All these commands are used in normal mode.
u | undo the last edit |
CTRL-r | redo the last edit (undo the last undo) |
U | undo all the edits in the last line edited
This only works on the last line edited. Once you make an edit to another line, this command then attaches itself to that line. You can undo and redo all changes you made to the last line edited as often as you want:
|
There are more ways to undo and redo, there is branching in the undo stack and you can go back and forth to specific times. Check out :help undo if you are interested. I won’t mention those commands here, that would be too big a bite to swallow at once.