In Vim, I did too much undo. How do I undo this (that is, redo)?
-
110as I already collected 2 close votes, I think this belongs here as vim is a programmer's editor. – flybywire Oct 12 '09 at 17:17
-
30I agree, this is programming-related *and* it's a real question. – DigitalRoss Oct 12 '09 at 17:19
-
44Someone around here goes around and marks every Vim question as "belongs on SU" despite the community having long ago decided that Vim belongs on SO, it being a programming tool. – Brian Carper Oct 12 '09 at 19:45
-
@Brian: Do you have a link to the document where this consensus was reached? – too much php Oct 13 '09 at 02:08
-
http://meta.stackexchange.com/questions/22963/where-should-developer-computer-setup-questions-go – geowa4 Oct 13 '09 at 12:47
-
12http://meta.stackexchange.com/questions/20251/where-to-ask-a-question-about-an-ide but I recall this coming up last year sometime. Vim/Emacs are IDEs. Moreover the languages used in the config files for both are Turing-complete scripting languages, so the act of setting up Vim is itself programming to begin with. – Brian Carper Oct 14 '09 at 17:38
-
@Elyasin: Existing questions are not migrated to new networks. – SabreWolfy Jul 18 '16 at 14:19
10 Answers
Ctrl+r

- 197,344
- 39
- 212
- 226
-
2I would just like to throw the undoTree plugin out there, super awesome for the times you have seemingly screwed yourself with a flurry of undos and redos. – Jake Sellers Jan 03 '14 at 05:31
-
3If I am reading about vi, then my fingers just act on their own. The vi commands do not work on stackoverflow. :-) – ciscogambo Jan 17 '14 at 21:17
-
3Note to Mac users: Ctrl + r in a Mac terminal will ruin your day in vim. Don't know the proper key combo in Mac terminal to undo, but it's most definitely NOT Ctrl + r ! – tpartee Nov 03 '17 at 23:58
-
@tpartee I just used Ctrl+r in vim under macOS's Terminal app - no problems here. – Jase Jan 12 '18 at 04:13
-
3Maybe @tpartee meant `Cmd + r` messes things up? It certainly does something weird; but `Ctrl + r` just worked fine for me (Mac + tmux + vim) – dwanderson Jun 07 '18 at 18:23
-
For some reason, in my case `Ctrl + r` sends Vim into the background process instead of un-doing. So I need to do `fg` in order to bring it back. Not sure what is the reason. Using `iTerm2` to connect an Ubuntu machine with `zsh` (and oh-my-zsh) installed. – devforfu Feb 21 '20 at 06:44
Also check out :undolist
, which offers multiple paths through the undo history. This is useful if you accidentally type something after undoing too much.

- 127,331
- 53
- 180
- 211
-
25@amindfv: take the number from `:undolist` and type `:undo 178` (say) to rewind to step 178. – Peter Dec 05 '12 at 22:41
-
is there any way to show what exactly will be undo'ed in `:undolist`? – csharpfolk Mar 04 '15 at 11:32
-
2
Use :earlier
/:later
. To redo everything you just need to do
later 9999999d
(assuming that you first edited the file at most 9999999 days ago), or, if you remember the difference between current undo state and needed one, use Nh
, Nm
or Ns
for hours, minutes and seconds respectively. + :later N<CR>
<=> Ng+
and :later Nf
for file writes.

- 30,738
- 21
- 105
- 131

- 52,536
- 7
- 114
- 135
-
1`:later` worked for me in `vi` (not vim -- searched for "vi" on google but all results are for "vim"), thanks! – Luc Jun 09 '14 at 18:49
-
@Luc Almost everywhere where you have `vi` command it is a symlink to a vim executable or a copy of it. Not completely everywhere though. – ZyX Jun 13 '14 at 06:23
-
@ZyX I wish that was true. I only use vi after bash throws a `vim: command not found`. Next thing I do is `alias vim=vi` because I type it so automatically, but it's the plain old vi nevertheless. Also, redo (ctrl+r) would have worked properly had vi been an alias for vim. – Luc Jun 13 '14 at 12:05
-
29999999d is 27395 years ago. I assume the undo feature was not implemented in vi back then. You might want to save yourself some exhaustive typing effort and use a reasonable number. 9999d correspongs to about 27 years, 999d to 2.7 years. I guess in most cases that's enough ... – ChristophK Jul 06 '18 at 09:08
<Undo> or *undo* *<Undo>* *u*
u Undo [count] changes. {Vi: only one level}
*:u* *:un* *:undo*
:u[ndo] Undo one change. {Vi: only one level}
*CTRL-R*
CTRL-R Redo [count] changes which were undone. {Vi: redraw screen}
*:red* *:redo* *redo*
:red[o] Redo one change which was undone. {Vi: no redo}
*U*
U Undo all latest changes on one line. {Vi: while not
moved off of it}

- 40,390
- 17
- 88
- 107
In command mode, use the U key to undo and Ctrl + r to redo. Have a look at http://www.vim.org/htmldoc/undo.html.
-
-
2@YuFengShen the power of vim is in the command mode. we don't need redo in insert mode – Tomas Hrubovcak Mar 05 '19 at 08:28
-
First press the Esc key to exit from edit mode.
Then,
For undo, use u key as many times you want to undo.
For redo, use Ctrl +r key

- 30,738
- 21
- 105
- 131

- 2,917
- 19
- 27
Refer to the "undo" and "redo" part of Vim document.
:red[o] (Redo one change which was undone) and {count} Ctrl+r (Redo {count} changes which were undone) are both ok.
Also, the :earlier {count} (go to older text state {count} times) could always be a substitute for undo and redo.

- 30,738
- 21
- 105
- 131

- 111
- 1
- 4
-
9Actually, it shouldn't matter -- traditional consoles have no distinction between `^r` and `^R`, and Vim follows that. – ephemient Oct 12 '09 at 19:43
-
@ephemient: agreed. In MS-DOS, you can't even type a lowercase `^X` (where `X` can be any letter). – alexia Jan 11 '11 at 18:33
-
Using VsVim for Visual Studio?
I came across this when experimenting with VsVim, which provides bindings for Vim commands in Visual Studio.
I know about Ctrlr in Vim itself, but this particular binding does not work in VsVim (at least not in my setup?).
What does work however, is the command :red
. This is a little bit more of a hassle than the above, but it is still fine when you really need it.

- 30,738
- 21
- 105
- 131

- 18,591
- 15
- 71
- 96
-
Downvoted because the question is asking specifically about vim, not Visual Studio. – John Von Neumann Nov 07 '18 at 23:24
-
5@JohnVonNeumann This *is* related to Vim, or at least vim bindings, just in the context of VS. That`s what brought me to this question, after all. Punishing someone for adding a little more info seems a little harsh and uncalled for don't you think, even if it does perhaps expand slightly beyond the scope of the OP? – Kjartan Nov 08 '18 at 07:47
-
Unfortunately this no longer seems to work? Quite annoying, as undo/redo's are something VsVim seems to be especially bad at – Josh Wright Sep 01 '21 at 16:46
Practically speaking, the :undolist
is hard to use and Vim’s :earlier
and :later
time tracking of changes is only usable for course-grain fixes.
Given that, I resort to a plug-in that combines these features to provide a visual tree of browsable undos, called “Gundo.”
Obviously, this is something to use only when you need a fine-grained fix, or you are uncertain of the exact state of the document you wish to return to. See: Gundo. Graph your Vim undo tree in style

- 30,738
- 21
- 105
- 131

- 10,969
- 2
- 30
- 42