vim Normal mode commands (Editing) Basic Undo and Redo

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Insert
> Step 2: And Like the video. BONUS: You can also share it!

Example

Undo

Command:Description
uu,undoUndo the most recent change
5uUndo 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.

Redo

Command:Description
Ctrl-Rred,redoRedo the most recent undone change
2Ctrl-RRedo 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.



Got any vim Question?