This is a read-only archive!

Emacs undo is horrible

Emacs has a, well, "unique" undo system. It only has undo, no redo. When you undo something, the act of undoing is added as itself onto a stack of undo actions. When you've un-done enough things, you do "something, like move the cursor, and that breaks the chain. From there if you undo again, you will traverse back over the undo actions you just did.

This is supposedly powerful. It does help with the following situation:

  • Type something.
  • Type something #2.
  • Type something #3.
  • Undo undo undo.
  • Type something #4.

In most programs once you reach step 4, you can redo to get back to the text you just undid But once you reach step 5, the first three things you typed are lost forever. You've gone back in time and changed history, eradicating the old future and replacing it with a new one. You can never get back to the old future. Emacs undo, on the other hand, where undo actions are just like any other actions and pushed onto a stack of actions, does let you undo back first three things you typed.

However in practice this doesn't work so well. This site has a nice quote:

?By [undoing] repeatedly, you can gradually work your way back to a point before your mistake. This is convenient if you?ve made a mistake four or five commands back. It is marginally useful if you?ve made a mistake twenty or thirty characters back. And it is completely useless if your mistake is ancient history.? - Learning GNU Emacs (page 42)

The problem being, supposing you undo 20 times, and break the chain (by moving the cursor for example), if you then decide to undo one step FURTHER back, you have to undo all 20 of your previous undos, undo 20 more times, then undo once more. Eventually you end up feeling like you're going up and down a roller coaster of undos.

If you hate this, which you probably do, you could use redo mode, which gimps up Emacs undo/redo to be like any other program's, i.e. you get the same behavior as Microsoft Notepad. (Although when I tried it, it was buggy as heck, failing to undo my actions properly, mangling text from different lines together and whatnot.)

Vim's undo system on the other hand is far better and equally powerful. You have a standard undo / redo option via u and CTRL-R. You also have a second completely different way to undo: you can "go back in time". In the above example, Vim will create two undo "branches" and you can jump from one to the other even if you undo and "break the chain" by typing something new.

Doing :undol lists the branches, in a somewhat confusing format. But you can just pound g- and g+ to go to older / newer text states, or use :earlier with a human-readable time (say, 10s or 5m) and it will take you to that point. These will get you all the power of Emacs' undo stack, with none of the pain or confusion. See also :h undo-two-ways.

This is one of many instances where Vim wins, hands-down. Vim's undo system isn't as reprogrammable as Emacs, but it's so powerful and so perfectly what you'd want that it doesn't matter. This is beautifully typical of Vim. I don't have a year to figure out all the nooks and crannies and edge cases and idiosyncrasies of Emacs undo system, let alone the time it'd take to write a custom, crusty elisp script to buggily re-implement it.

Being an "extensible text editor" doesn't help much when such basic functionality is so broken. Unless you want to play your undo history back like a movie, in rainbow colors, which I don't. I want undo/redo that works.

May 25, 2008 @ 3:54 PM PDT
Cateogory: Programming
Tags: Emacs, Vim

18 Comments

Adam Sloboda
Quoth Adam Sloboda on May 25, 2008 @ 4:51 PM PDT

I can't see how vim way is more comfortable in everyday use. For me, that far too complex system would be PITA for such simple tasks I do with (Emacs') infinite undo (and yes, I find myself using and enjoying the "infinite" feature as opposed to undo-redo-"end-of-history" quite frequently).

Aidan Kehoe
Quoth Aidan Kehoe on May 25, 2008 @ 5:24 PM PDT

You can avoid this: http://www.emacswiki.org/cgi-bin/wiki/RedoMode . I agree that it?s a stupid default.

Eric TF Bat
Quoth Eric TF Bat on May 25, 2008 @ 7:39 PM PDT

You don't like it because you're not used to it. Fortunately, it's Emacs, so you can change it. I do like it, and I use it all the time, and not having the option to change it would be hopeless... which is why I don't use vi.

Emacs: because grownups like having choices.

ast_tree
Quoth ast_tree on May 25, 2008 @ 8:47 PM PDT

Eric, I hope you don't use Gnome.

I don't.

Penguin Pete
Quoth Penguin Pete on May 25, 2008 @ 10:33 PM PDT

Oh, come on. I've been using Emacs for 15 years, and had maybe one incident where I needed to re-do something I'd undone in more than one step. Petty problem.

And comparing it with Microsoft Notepad isn't going to win you points with either user base. :)

Joe
Quoth Joe on May 25, 2008 @ 10:53 PM PDT

You don't state very clearly what problem you have with the current system. It seems to be related with the quantity of "undos" sometimes necessary to return to a certain state. But in most editors, you would simply be unable to return to most states, so that is really a win for emacs.

I very frequently return to "ancient" mistakes with emacs's undo, and it just doesn't bother me at all. I hold down the undo key and zip through the history to get where I want to go.

The vim stuff you describe sounds interesting, but from what I can see, emacs lets you get anywhere in your history with one key, whereas vim requires multiple commands that even a proponent like yourself find confusing. So ... I'm not in a rush to try it out.

blastura
Quoth blastura on May 25, 2008 @ 11:00 PM PDT

Emacs have redo C-u C-x u

Steven G. Harms
Quoth Steven G. Harms on May 25, 2008 @ 11:28 PM PDT

I'm a former emacs user and yes, I agree, the undo is pretty broken.

Everything I care to say on my thought process around this decision can be found at: http://stevengharms.com/emacs-v-vi-is-rooted-in-the-love-of-lisp

LV
Quoth LV on May 26, 2008 @ 12:07 AM PDT

The undo has worked fine for me so far. I assumed to access the various undo branches I would just have to think harder about what it was I wanted to do. If you can work up a test case I'm sure we can follow it through to reproduce it but my guess is it will just act as a learning exercise and reinforce that the system is ok.

jtek
Quoth jtek on May 26, 2008 @ 1:04 AM PDT

It would really be nice if somebody ported the undo functionality of e-texteditor (the source of the initial quote), to emacs. Having gotten used to the visual undo history with branches and synopsis of each change, where you can freely jump around in the history, going back to broken undo system in emacs is really jarring.

Sigmoid Fraud
Quoth Sigmoid Fraud on May 26, 2008 @ 2:11 AM PDT

Strong unconscious impulses. It's obvious that your fathers are opressive powerful archetypes or that you are beeing bitten by a horse at young age. Do you feel sexual desire for the parent of the opposite sex or desire the death of the parent of the same sex?

James
Quoth James on May 26, 2008 @ 2:28 AM PDT

@jtek - Just use a version control system, and make frequent commits. Undo should just be what that name implies... to undo changes.

Jim Radford
Quoth Jim Radford on May 26, 2008 @ 2:56 AM PDT

A lesser known feature of emacs undos can be restricted to the current region. If you've bounced around editing different functions, but you just want to undo the changes within one particular function, you just have to select it and undo. This can significantly prune the undo tree in many cases.

Brian
Quoth Brian on May 26, 2008 @ 4:14 AM PDT

Penguin Pete: You really never undo more than one step? I can't say the same.

Joe: I gave a poor representation of Vim's undo system. u and CTRL-R are all you need 99% of the time. g- and g+ are good enough the other 1% of the time when u and CTRL-R don't work. Those commands get you everything Emacs can do. The other things I listed are just icing.

TheGZeus
Quoth TheGZeus on May 26, 2008 @ 6:37 AM PDT

>Quoth ast_tree:

>Eric, I hope you don?t use Gnome.

>I don?t.

HAHA! Yeah. It's hilarious that GNU project software tends to either be either text-mode software with everything and 12 kitchen sinks, or 1/3 of a GUI progam, with the other 2/3 having been removed because they're too confusing, or something. "You want to use a mouse? You must be stupid! We'd better hide or remove anything we doubt you'd use!"

Kristian
Quoth Kristian on May 26, 2008 @ 7:48 AM PDT

Emacs supports local undo, you can mark a region where you want to undo/redo. This helps a LOT, since it's no longer so bad if your change was 20 lines of changes away from the current change.

Eric TF Bat
Quoth Eric TF Bat on May 26, 2008 @ 8:25 AM PDT

Heh. As it happens, I don't use Gnome. I switched to KDE for precisely that reason: that Gnome's designers feel it's their job to decide how everyone should work. KDE gives you sensible defaults, plenty of options and a much more responsive and flexible system all round. Like Emacs, really.

Brian
Quoth Brian on May 26, 2008 @ 8:35 AM PDT

Vim itself is a marvel of flexibility. You can remap every key, you can write functions in Vimscript or Ruby or Python or Perl to extend its behavior, you can change thousands of options to customize how it works. The only thing more flexible than Vim is Emacs, but Vim is still an achievement in that area.