• Modern UX

    Edit and navigate faster in the terminal with Warp's IDE-like input editor.

  • Warp AI

    AI suggests what commands to run and learns from your documentation.

  • Agent Mode

    Delegate tasks to AI and use natural language on the command line.

  • Warp Drive

    Save and share interactive notebooks, workflows, and environment variables.

  • All Features

Undo & Redo in Vim / Vi

Thumbnail for Jessica WangJessica Wang

Jessica Wang

Developer Advocate, Warp

Published: 1/31/2024

About Terminus

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. 1. Press esc to return to normal mode. Any character typed in normal mode will be interpreted as a vim command.
  2. 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. 1. Press esc to return to normal mode. Any character typed in normal mode will be interpreted as a vim command.
  2. 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.

Written by

Thumbnail for Jessica WangJessica Wang

Jessica Wang

Developer Advocate, Warp

Filed Under

Related Articles

Vim Find And Replace

You can use either the substitute command or the slash and dot method to search for patterns and replace with different values.

VimVi
Thumbnail for Glory KimGlory Kim

Vim Modes

Learn about seven of Vim’s modes

VimVi
Thumbnail for Razvan LudosanuRazvan Ludosanu

Vim / Vi Page Up and Down Controls

Quick reference for Vim's page up and down controls

VimVi
Thumbnail for Glory KimGlory Kim

Copy & Paste in Vim / Vi

Copy (Yank), Paste (Put) and Cut (Delete) in Vim

VimVi
Thumbnail for Jessica WangJessica Wang

Show & Hide Line Numbers in Vim / Vi

Toggle absolute and relative line numbers

VimVi
Thumbnail for Amber ChenAmber Chen

Select all in Vim / Vi

Select all and copy, paste, or delete the contents

VimVi
Thumbnail for Glory KimGlory Kim

Searching in Vim

Search forward, backward, case insensitive, and more

VimVi
Thumbnail for Neeran GulNeeran Gul

Go To End of File in Vim / Vi

Select and delete to the end of a file in Vim

VimVi
Thumbnail for Preston Tunnell WilsonPreston Tunnell Wilson

How to delete lines in Vim / Vi

The best answer depends on which mode you use

VimVi
Thumbnail for Andrew CarlsonAndrew Carlson

Trusted by hundreds of thousands of professional developers

Download Warp to get started

Download for Mac
Thumbnail for null