How to undo in Vim editor in Linux
Last Updated :
25 Sep, 2023
Vim (short for Vi Improvised) is a popular text editor mainly used in Linux and Unix-based operating systems but due to having a CLI (command line interface), it might be difficult for new users to make use of basic features such as undo in Vim. So in this article, we will learn different ways and types to undo changes in Vim Editor in Linux.
Like all other modern text editors, Vim also has the functionality UNDO which enables the users to revert the changes done in the document. It saves the changes as revisions or entries in the memory so that when asked, it can revert the current revision to the previous revision.( basically undoing changes).
Vim has also a criterion of what is to be considered an entry or revision. Any of the following can be considered an entry:
- Pressing i to move into insert mode.
- Writing 4 new lines in insert mode.
- Editing 4 different lines in insert mode.
How to Undo in Vim Editor?
Vim not only offers basic undo function, but also of various types with different affects. We can undo changes in three different ways:
- Undo Most Recent Change
- Undo Multiple Changes
- Undo All Changes in a Single Line
Lets look at each of them one by one.
1. Undo Most Recent Change
In this method, we undo the last change we did on the document. In other words, we revert to the most recent revision of the document.
Command
u or :u or :undo
To do this, follow the given steps:
- Press Esc - To exit the insert mode and come to the normal mode.
- Enter u, :u or :undo - To enter undo the latest change.
Before Undo
- You can see the most recently done changes are reverted.
After Undo
2. Undo Multiple Changes
We can also undo multiple changes in a single command.
Command
Nu or :undo N
where N is the number of changes you want to undo.
Follow the given steps to do undo multiple changes in one go:
- Press Esc - To exit the insert mode and come to the normal mode.
- Enter 3u or :undo 3 - To undo the last 3 changes.
Before Undo
- As you can see, the current revision is reverted to the third most recent revision.
After Undo
3. Undo All Changes in a Single Line
This method allows the user to undo all the changes in a Single Line.
Command
U
Follow the given steps to undo all the changes in a Single Line:
- Press Esc - To exit the insert mode and come to the normal mode.
- Enter U - To undo all the changes in the given line.
Before Undo- As we can see, all the changes in the single line are reverted.
Listing All Undo Branches
After undo, we do some more changes and overwrite the last done changes with current changes. Generally, there is no way to access those removed changes but in Vim, these changes are not completely deleted but instead, their entries get branched into different undo branches. We can view and access these branches using the following command:
:undolist
Example
UndolistConclusion
Undo is one of the basic operations in any text editor, and Vim has a powerful version of it that offers more capabilities as compared to other editors. This article discusses the different undo types in Vim, which can help you improve your productivity.
Similar Reads
Non-linear Components
In electrical circuits, Non-linear Components are electronic devices that need an external power source to operate actively. Non-Linear Components are those that are changed with respect to the voltage and current. Elements that do not follow ohm's law are called Non-linear Components. Non-linear Co
11 min read
Spring Boot Tutorial
Spring Boot is a Java framework that makes it easier to create and run Java applications. It simplifies the configuration and setup process, allowing developers to focus more on writing code for their applications. This Spring Boot Tutorial is a comprehensive guide that covers both basic and advance
10 min read
Class Diagram | Unified Modeling Language (UML)
A UML class diagram is a visual tool that represents the structure of a system by showing its classes, attributes, methods, and the relationships between them. It helps everyone involved in a projectâlike developers and designersâunderstand how the system is organized and how its components interact
12 min read
Steady State Response
In this article, we are going to discuss the steady-state response. We will see what is steady state response in Time domain analysis. We will then discuss some of the standard test signals used in finding the response of a response. We also discuss the first-order response for different signals. We
9 min read
Backpropagation in Neural Network
Back Propagation is also known as "Backward Propagation of Errors" is a method used to train neural network . Its goal is to reduce the difference between the modelâs predicted output and the actual output by adjusting the weights and biases in the network.It works iteratively to adjust weights and
9 min read
Polymorphism in Java
Polymorphism in Java is one of the core concepts in object-oriented programming (OOP) that allows objects to behave differently based on their specific class type. The word polymorphism means having many forms, and it comes from the Greek words poly (many) and morph (forms), this means one entity ca
7 min read
3-Phase Inverter
An inverter is a fundamental electrical device designed primarily for the conversion of direct current into alternating current . This versatile device , also known as a variable frequency drive , plays a vital role in a wide range of applications , including variable frequency drives and high power
13 min read
What is Vacuum Circuit Breaker?
A vacuum circuit breaker is a type of breaker that utilizes a vacuum as the medium to extinguish electrical arcs. Within this circuit breaker, there is a vacuum interrupter that houses the stationary and mobile contacts in a permanently sealed enclosure. When the contacts are separated in a high vac
13 min read
AVL Tree Data Structure
An AVL tree defined as a self-balancing Binary Search Tree (BST) where the difference between heights of left and right subtrees for any node cannot be more than one. The absolute difference between the heights of the left subtree and the right subtree for any node is known as the balance factor of
4 min read
Linux Commands Cheat Sheet
Linux, often associated with being a complex operating system primarily used by developers, may not necessarily fit that description entirely. While it can initially appear challenging for beginners, once you immerse yourself in the Linux world, you may find it difficult to return to your previous W
13 min read