> ## Content Index
> Fetch the complete content index at: https://itsfoss.com/llms.txt
> Use this file to discover other available public pages before exploring further.

# Undo and Redo in Vim
- URL: https://itsfoss.com/vim-undo-redo/
- Published: 2023-10-22T04:12:59.000Z
- Updated: 2023-10-22T04:12:59.000Z
- Description: To err is human. To undo is the error is super human.
- Author: Sagar Sharma
- Tags: Vim, #hide

Let me guess. 

You made some mistakes while editing a file in Vim and now looking for a way to undo the previous action. Right?

Well, it is pretty easy to undo and redo in Vim and can be done by following the given keybindings:

| **Action** | **Description**           |
| ---------- | ------------------------- |
| u          | Undo the last action.     |
| Ctrl + r   | Redo the previous action. |

**Make sure you use these shortcuts in the normal mode (activated by pressing the `Esc` key).** 

Want a detailed explanation? I got you!

## How to undo in Vim 

To undo in Vim, all you have to do is follow the given steps:

1. Press the `Esc` key to switch to the normal mode
2. Press the `u` key to undo the last action (press it multiple times to undo earlier actions).

For example, here, I removed lines 3, 5, and 7 and now want to undo them so I will press the `u` key 3 times:

![Undo in the vim editor](https://itsfoss.com/content/images/2023/10/Undo-in-Vim-editor.gif)

As you can see when I pressed the `u` key multiple times, it brought back all the deleted lines and when I pressed it again, it said `Already at oldest change`.

It simply means you brought the file to the previously saved position and if that's the new file and you keep pressing the `u` key, it will remove all the lines. 

But if you don't want to keep pressing the `u` key, then you can specify how many times you want to perform undo at once by appending the number.

For example, if I want to undo the last 3 actions, then I will have to enter `3u` (first, enter 3 and then u):

![undo multiple actions in Vim ](https://itsfoss.com/content/images/2023/10/Undo-multiple-actions-at-once-in-the-vim-editor.gif)

[Icedrive - Next-Generation Cloud Storage - Get 10GB FreeNext-Generation cloud storage with Icedrive. Get started right away with a massive 10GB free space.![](https://icedrive.net/apple-touch-icon.png)icedrive![](https://icedrive.net/frontend/img/icon-sm.png)](https://icedrive.net/?pt=q7io5geg9t&ref=itsfoss.com)

Partner Link

## How to redo in Vim 

For those who don't know, redo is used to revert the action done by undo. I mean you may have pressed the `u` key accidentally or you just changed your mind about the undo action itself.

In that case, simply follow these two steps:

1. Switch to normal mode (if you haven't already)
2. Press `Ctrl + R` to redo the action

For example, I used undo to get back lines that I deleted accidentally so now, I will use `Ctrl + r` 3 times to remove them again: 

![redo in vim](https://itsfoss.com/content/images/2023/10/Use-redo-in-the-Vim-editor.gif)

As you can see when I pressed `Ctrl + r`, it reverts the action done by undo and when I pressed it more than the required times, it said `Already at newest change`.

Which simply means there is nothing left to redo.

Similar to undo, you can also specify how many times you want to perform the redo action at once. 

For that, you have to first enter the number of how many times you want to perform redo and then press `Ctrl + r` which will look like this: `number + Ctrl + r`.

Let's say I want to perform redo 3 times, so I will use `3 + Ctrl + r`:

![redo multiple times in Vim](https://itsfoss.com/content/images/2023/10/Redo-multiple-times-at-once-in-Vim.gif)

Pretty convenient. Right?

## Here's how to master Vim 

If you want to master Vim and want to flaunt your skills, you have to start from scratch and learn all the basics first and for that, you can [refer to our detailed guide on Vim commands:](https://linuxhandbook.com/basic-vim-commands/?ref=itsfoss.com)

[Basic Vim Commands Every Linux User Must Know \[With PDF Cheat Sheet\]A comprehensive guide explaining basic vim commands that will be useful to any Linux user be it a sysadmin or a developer.![](https://linuxhandbook.com/content/images/size/w256h256/2021/08/Linux-Handbook-New-Logo.png)Linux HandbookAbhishek Prakash![](https://linuxhandbook.com/content/images/2020/06/basic-vim-command-guide-1.jpeg)](https://linuxhandbook.com/basic-vim-commands/?ref=itsfoss.com)

Once you are done with the basics, here are some tips to get to the next level:

[8 Vim Tips And Tricks That Will Make You A Pro UserBrief: In this article, I’ll show you some of my favorites Vim tricks with practical examples. If you don’t use Vim, these tips might not give reasons for using Vim but if you use it already, you’ll definitely become a better Vim user. Even if I recently![](https://itsfoss.com/content/images/size/w256h256/2022/12/android-chrome-192x192.png)It's FOSSSylvain Leroux![](https://itsfoss.com/content/images/wordpress/2017/02/vim-tips-tricks.jpg)](https://itsfoss.com/pro-vim-tips/)

And if you want to take it even further, here's an excellent Vim course for you.

![](https://itsfoss.com/content/images/2023/10/mastering-vim-quickly-book.jpg) 

#### Mastering Vim Quickly

Master Vim like a true professional with this highly rated, premium Vim book and training course.

[Chek it out](https://itsfoss.click/mastering-vim-quickly?ref=itsfoss.com) 

I hope you will find this guide helpful.