Undo in Emacs

There are a variety of ways to “undo” something in Emacs.  Unfortunately some of the keystrokes work in some environments, while others do not.  Here’s a quick rundown:

  1. Meta-x undo — Will undo only the most recent changes.  Cannot be used multiple times.
  2. Ctrl-x u — Undo.  Consecutive repetitions will undo earlier and earlier changes.
  3. Ctrl-_ or Ctrl-/ — Same as Ctrl-x u, however does not work in some envrionments.
  4. Ctrl-Shift-Minus — Same as Ctrl-x u, however does not work in some environments.

For whatever reason I can never remember the Ctrl-Shift-Minus sequence when I find myself in an environment where Ctrl-_ and Ctrl-/ don’t work.

Keep in mind that Emacs undo is a bit different from traditional undo:  Undo actions themselves are recorded as actions.  This can be confusing.

In some environments, Ctrl-x Ctrl-_ will reverse the order of undo.  I avoid this out of fear that it will cause the universe to implode.

See the Emacs info node for more good undo lore, such as how to use “selective undo” which restricts undo actions to changes performed in the current active region.  (Very useful.)

Leave a Reply

Your email address will not be published. Required fields are marked *