How do I do redo (i.e. "undo undo") in Vim?
311,772
Solution 1
Ctrl+r
Solution 2
Also check out :undolist
, which offers multiple paths through the undo history. This is useful if you accidentally type something after undoing too much.
Solution 3
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.
Solution 4
<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}
Solution 5
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.
Author by
flybywire
Updated on January 16, 2020Comments
-
flybywire over 4 years
In Vim, I did too much undo. How do I undo this (that is, redo)?
-
ephemient over 14 yearsActually, it shouldn't matter -- traditional consoles have no distinction between
^r
and^R
, and Vim follows that. -
alexia over 13 years@ephemient: agreed. In MS-DOS, you can't even type a lowercase
^X
(whereX
can be any letter). -
Peter over 11 years@amindfv: take the number from
:undolist
and type:undo 178
(say) to rewind to step 178. -
Jake Sellers over 10 yearsI 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.
-
ciscogambo over 10 yearsIf I am reading about vi, then my fingers just act on their own. The vi commands do not work on stackoverflow. :-)
-
Luc almost 10 years
:later
worked for me invi
(not vim -- searched for "vi" on google but all results are for "vim"), thanks! -
ZyX almost 10 years@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. -
Luc almost 10 years@ZyX I wish that was true. I only use vi after bash throws a
vim: command not found
. Next thing I do isalias 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. -
csharpfolk about 9 yearsis there any way to show what exactly will be undo'ed in
:undolist
? -
Admin over 6 years@csharpfolk Use the undotree plugin (github.com/mbbill/undotree)
-
tpartee over 6 yearsNote 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 !
-
Jase over 6 years@tpartee I just used Ctrl+r in vim under macOS's Terminal app - no problems here.
-
dwanderson almost 6 yearsMaybe @tpartee meant
Cmd + r
messes things up? It certainly does something weird; butCtrl + r
just worked fine for me (Mac + tmux + vim) -
ChristophK almost 6 years9999999d 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 ...
-
John Von Neumann over 5 yearsDownvoted because the question is asking specifically about vim, not Visual Studio.
-
Kjartan over 5 years@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?
-
YuFeng Shen about 5 yearsHow about in insert mode?
-
Tomas Hrubovcak about 5 years@YuFengShen the power of vim is in the command mode. we don't need redo in insert mode
-
Paul Stelian over 4 yearsIn Vim, Ctrl-shift-R (ctrl with uppercase R) is replace mode.
-
Peter Mortensen over 4 yearsThe link is (effectively) broken.
-
devforfu about 4 yearsFor some reason, in my case
Ctrl + r
sends Vim into the background process instead of un-doing. So I need to dofg
in order to bring it back. Not sure what is the reason. UsingiTerm2
to connect an Ubuntu machine withzsh
(and oh-my-zsh) installed. -
Joshua Wright over 2 yearsUnfortunately this no longer seems to work? Quite annoying, as undo/redo's are something VsVim seems to be especially bad at