This article has the mention that "We say Emacs has redo because you can reverse direction while undoing, thereby undoing the undo.".
What does this mean? How can the user can 'redo' with emacs?
This article has the mention that "We say Emacs has redo because you can reverse direction while undoing, thereby undoing the undo.".
What does this mean? How can the user can 'redo' with emacs?
If you perform some command (even a navigation command such as C-f
) after a sequence of undo operations, all the undos are pushed on to the operation stack. So the next undo undoes the last command. Suppose you do have an operation sequence that looks like this:
Now, you undo. It undoes the last action, resulting in the following list:
If you do something other than undo at this point - say, C-f
, the operation stack looks like this:
Now, when you undo, the first thing that is undone is the undo. Resulting in your original stack (and document state):
If you do a modifying command to break the undo sequence, that command is added after the undo and is thus the first thing to be undone afterwards. Suppose you backspaced over "bar" instead of hitting C-f
. Then you would have had
This adding/re-adding happens ad infinitum. It takes a little getting used to, but it really does give Emacs a highly flexible and powerful undo/redo mechanism.
To undo : C-_
To redo after a undo : C-g C-_
Type multiple times on C-_
to redo what have been undone by C-_
To redo an emacs command multiple times, execute your command then type C-x z
and then type many times on z
key to repeat the command (interesting when you want to execute multiple times a macro)
I find redo.el
extremly handy for doing "normal" undo/redo, and I usually bind it to C-S-z and undo to C-z, like this:
(when (require 'redo nil 'noerror)
(global-set-key (kbd "C-S-z") 'redo))
(global-set-key (kbd "C-z") 'undo)
Just download the file, put it in your lisp-path and paste the above in your .emacs
.
For those wanting to have the more common undo/redo functionality, someone has written undo-tree.el
. It provides the look and feel of non-Emacs undo, but provides access to the entire 'tree' of undo history.
I like Emacs' built-in undo system, but find this package to be very intuitive.
Here's the commentary from the file itself:
Emacs has a powerful undo system. Unlike the standard undo/redo system in most software, it allows you to recover any past state of a buffer (whereas the standard undo/redo system can lose past states as soon as you redo). However, this power comes at a price: many people find Emacs' undo system confusing and difficult to use, spawning a number of packages that replace it with the less powerful but more intuitive undo/redo system.
Both the loss of data with standard undo/redo, and the confusion of Emacs' undo, stem from trying to treat undo history as a linear sequence of changes. It's not. The `undo-tree-mode' provided by this package replaces Emacs' undo system with a system that treats undo history as what it is: a branching tree of changes. This simple idea allows the more intuitive behaviour of the standard undo/redo system to be combined with the power of never losing any history. An added side bonus is that undo history can in some cases be stored more efficiently, allowing more changes to accumulate before Emacs starts discarding history.