Terminus by Warp
Undo & Redo in Vim / Vi

Undo & Redo in Vim / Vi

Jessica Wang
Jessica Wang
Developer Advocate, Warp

Understanding How Vim Tracks Changes Conceptually

Vim tracks changes by entries. An entry in Vim is defined as anything you can do within a session in insert mode before returning to normal mode, or a command you use in normal mode.

Each of the following examples below can be considered 1 entry:

  • Pressing i to move into insert mode
  • Writing 4 new lines in insert mode
  • Editing 4 different lines in insert mode

To clarify, here is what is not considered an entry:

  • Typing one character, then continuing to type in insert mode. Vim will not work like your normal text editor (Google Docs or Notion) where you can undo typing character by character unless you switch to normal mode then back to insert mode (thus ending and starting a new entry) per character.

Undo Changes in Vim / Vi

  1. Press esc to return to normal mode. Any character typed in normal mode will be interpreted as a vim command.
  2. Press u, :u, or :undo to undo the last change (entry). The reason why it is important to be in normal mode is because pressing u in another mode may trigger different results, like turning the selected characters lowercase.

Redo Changes in Vim / Vi

  1. Press esc to return to normal mode. Any character typed in normal mode will be interpreted as a vim command.
  2. Press CTRL+r to redo the last change (entry).

Advanced Usage of Vim Undo/Redo Shortcuts

Undo

  • U: Undo latest changes to one line. This command is unique because it will create a new entry instead of reverting back to an old entry. This means you can actually press u to undo the changes done with U.
  • 4u: Undo last 4 changes (You can change 4 to any number to undo that number of changes)

Redo

  • 4CTRL+R: Redo last 4 changes (You can change 4 to any number to undo that number of changes)

Conclusion

This should be everything you need to undo and redo in Vim / Vi, which is a fundamental skill that every Vim user should know. If you didn’t find what you were looking for, it may be worth checking out the official vim docs.

Experience the power of Warp

  • Write with an IDE-style editor
  • Easily navigate through output
  • Save commands to reuse later
  • Ask Warp AI to explain or debug
  • Customize keybindings and launch configs
  • Pick from preloaded themes or design your own
brew install --cask warp
Copied!
Join the Windows waitlist:
Success! You will receive an email from Warp when the release is available to download.
Oops! Something went wrong while submitting the form.
Join the Linux waitlist:
Success! You will receive an email from Warp when the release is available to download.
Oops! Something went wrong while submitting the form.
Join the Linux waitlist or join the Windows waitlist
Join the Windows waitlist:
Success! You will receive an email from Warp when the release is available to download.
Oops! Something went wrong while submitting the form.