Command | : | Description |
---|---|---|
u | u ,undo | Undo the most recent change |
5u | Undo the five most recent changes (use any number) |
Please be aware that in Vim, the 'most recent change' varies according to the mode you are in. If you enter Insert Mode (i) and type out an entire paragraph before dropping back to Normal Mode (Esc), that entire paragraph is considered the most recent change.
Command | : | Description |
---|---|---|
Ctrl-R | red ,redo | Redo the most recent undone change |
2Ctrl-R | Redo the two most recent undone changes (use any number) |
There is one other way to undo and redo changes in Vim that is handled a bit differently. When you undo a change with u, you traverse back up the nodes on a 'tree' of your changes, and pressing Ctrl-R walks back down those nodes in order. (The undo tree is a separate topic and is too complex to cover here.)
You can also use U (that is, uppercase) to remove all the latest changes on a single line (the line where your last changes were made). This does not traverse the nodes of the tree in the same way as u. Using U actually counts as a change itself - another node forward on the tree - so that if you press U a second time immediately after the first it will act as a Redo command.
Each has its uses, but u / :undo
should cover most simple cases.