Undoing and redoing
Undoing and redoing are operations so common while editing files that we don’t think about them much. Most software however have a poor undo/redo system in which edits get lost all the time.
Emacs’ undos never loses edits and undo-tree brings a wonderful undo/redo system to it.
Undo systems
Linear systems: classic undo/redo
Linear systems: Emacs
Non linear system: undo-tree
And this is an exceedingly simple example only involving 5 different file states. I let you imagine how it quickly explodes in complexity in real life situations 🙂
Now, the default Emacs system has the huge benefit to never lose any edit. It is already a huge improvement over the default system on most software! The thing is that when we undo and redo changes, linear systems are not ideal. A tree structure that can be fully navigated is just a more sensible solution.
Undo-tree was initially developed for Vim, so Vim can also use an ideal undo/redo system.
Installing and customizing undo-tree
This is a personal affair.
The minimal configuration when using straight (to download the package) and use-package to load it and customize it, looks like this:
use-package undo-tree
(t) :straight
My personal configuration looks like this:
use-package undo-tree
(t
:straight
:init1)
(global-undo-tree-mode "C-l" . undo-tree-undo)
:bind (("C-r" . undo-tree-redo)
("s-t" . undo-tree-visualize)
(
:map undo-tree-visualizer-mode-map;; go to selected undo state
"<return>" . undo-tree-visualizer-quit)
(;; cancel (return to state before calling undo-tree-visualize)
"q" . undo-tree-visualizer-abort))) (