vim tip: How to undo and redo changes

Written by
Date: 2012-07-13 07:21:32 00:00


Vim is a great text editor, some love it, some hate it, it is one of the two most used text editors in Linux, the other one is Emacs.

Vim is usually already installed on your system, I use it on Linux and on my Mac too.

It does not have a menu, and works with commands and key-bindings, when you make a mistake or want to undelete something, then you want to undo the last done action.

The command to undo is:

:u

Or

:undo

If you are typing when you dicide you want to undo something, then you have to exit the insert mode, you do that by pressing the ESC key, and then writing :u

The undo command will not only undo one action, I mean if you happen to enter a lot of characters, then :u will delete all those, it can also be a complete paragraph, actually everything done since you enter in insert mode

But, you can also redo, and do again what has been undone. To do that and fast forward again, press CTRL+R, or enter :redo while not in insert mode, if you are in that mode, press ESC key before, and then enter :redo.

If you want to redo the last 3 undone changes, press 3 and then CTRL+R