How do I do redo (i.e. "undo undo") in Vim?

VimUndoRedo

Vim Problem Overview


In Vim, I did too much undo. How do I undo this (that is, redo)?

Vim Solutions


Solution 1 - Vim

Ctrl+r

Solution 2 - Vim

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 - Vim

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 - Vim

Vim documentation

<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 - Vim

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.

Solution 6 - Vim

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

Solution 7 - Vim

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.

Solution 8 - Vim

CTRL+r

The "r" is lower-case.

Solution 9 - Vim

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.

Solution 10 - Vim

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionflybywireView Question on Stackoverflow
Solution 1 - VimJohn MillikinView Answer on Stackoverflow
Solution 2 - VimPeterView Answer on Stackoverflow
Solution 3 - VimZyXView Answer on Stackoverflow
Solution 4 - Vimgeowa4View Answer on Stackoverflow
Solution 5 - VimXinusView Answer on Stackoverflow
Solution 6 - VimAmol UdageView Answer on Stackoverflow
Solution 7 - VimwangxinalexView Answer on Stackoverflow
Solution 8 - VimmimetnetView Answer on Stackoverflow
Solution 9 - VimKjartanView Answer on Stackoverflow
Solution 10 - VimgregoryView Answer on Stackoverflow