I normally undo with ctrl+_ with other editors there is a redo operation normally associated with ctrl+y. is there an emacs equivalent?

In general what is the best way to handle an "undo tree"?

  • Are you actually using the undo-tree package? With default Emacs behavior there is no redo command. You can make another edit (hit SPC or whatever) and then call undo as many times as needed to get back to what you want. – glucas Jun 25 '17 at 12:23
  • You can certainly use something like undo-tree, if you really think you need a specific redo feature. Most Emacs users just undo the undo to get pretty much the usual effect of a redo. E.g. C-_ to undo, followed by something else (e.g. insert a char), which breaks out of undoing, followed by C-_ twice, to undo the inserted char and undo the first undo. – Drew Jun 25 '17 at 15:50

The commentary at the outset of the undo-tree.el library describes two built-in methods to undo and redo: https://github.com/emacsmirror/undo-tree/blob/master/undo-tree.el#L87

;; C-_  C-/  (`undo-tree-undo')
;;   Undo changes.
;; M-_  C-?  (`undo-tree-redo')
;;   Redo changes.

The mode key map does not follow the normal naming convention, and instead the map is named undo-tree-map. You can set up any keyboard shortcut that you want.

Q: In general what is the best way to handle an "undo tree"?

A: Read the commentary once for a general understanding, and then read it again a second time to catch anything you may have missed the first time around. Beware that killing the visualization buffer by brute force leaves #<marker in no buffer> in the buffer-undo-tree and that causes read to choke when trying to restore from a saved history file if using the persistent save/restore feature. Older versions of the yasnippet library leave #<overlay in no buffer> inside the buffer-undo-tree that can make their way into the saved history file, which cause the same problem with persistent save/restore. [@npostavs has provided a link in the comment below to the yasnippet pull request that resolves unreadable leftovers remaining in the buffer-undo-tree.] To kill the visualization buffer, either type the letter q in the visualization buffer, or edit the parent buffer and it will close automatically -- kill-buffer is what I meant by brute force. There are some other bugs, but it is a fun library to play with. Rumor has it that someone forked it and is working on certain new features and bug fixes ....

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.