Emacs: Best Undo/Redo Mode

By Xah Lee. Date: . Last updated: .

There are a few packages for redo. Of the ones i've used are:

The redo.el works ok, but occasionally it corrupts your undo… meaning that you know there's more undo/redo but wasn't able to get to it. This happens perhaps once a month.

The redo+.el is supposed to update/modernize the code. Unfortunately, i didn't have luck with it. These Kyle based redo modes are ≈200 lines of elisp, each.

The undo-tree.el i just installed today, and it seems the best of the bunch. It includes a redo command “undo-tree-redo”. Plus, it gives you commands to visualize the full emacs undo tree.

Installing undo-tree-mode

If you have emacs 24, you can install undo-tree-mode from the MELPA repository. 〔►see Emacs: How to Install Packages Using ELPA, MELPA

Or, download “undo-tree-mode” at http://www.dr-qubit.org/tags/computing-code-emacs.html

then, place it at ~/.emacs.d/lisp/undo-tree.el. (create the dirs if they don't exist.)

then, place the following in your emacs init file:

;; Tell emacs where is your personal elisp lib dir
(add-to-list 'load-path "~/.emacs.d/lisp/")

(require 'undo-tree)
(global-undo-tree-mode 1)

〔►see How to Install Emacs Package Manually

By default, the keys to undo are {【Ctrl+/】, 【Ctrl+_】}. The keys to redo are: {【Ctrl+?】, 【Meta+_】}

Setting Up Undo Redo Keys

You can set them to the Z key:

(defalias 'redo 'undo-tree-redo)
(global-set-key (kbd "C-z") 'undo) ; 【Ctrl+z】

(global-set-key (kbd "C-S-z") 'redo) ; 【Ctrl+Shift+z】;  Mac style

(global-set-key (kbd "C-y") 'redo) ; 【Ctrl+y】; Microsoft Windows style

undo-tree-mode.el is written by Toby Cubitt. Thanks Toby.

Thanks to David Capello for suggesting undo-tree-mode.

Like it? Buy Xah Emacs Tutorial. Thanks.

or, buy something from Best Keyboard for Emacs