I haven't been able to find anything on the internet mentioning Eclipse's Undo functionality being broken/rubbish, so maybe it's just me. However, I thought I'd ask here and see if anyone else has experienced similar irritation and/or know of a fix.

The most common scenario is that I write a line of code, say:


After writing someString I press enter, which would normally take me to the end of the line / outside the println argument brakets. However, if I've somehow lost the special box highlight around the argument (e.g. by pressing escape) then enter will give me a new line before the closing bracket. If I now undo with Ctrl-Z this will undo the newline and the entire word (someString in this case). I now have the option of redoing and then manually deleting the newline, or typing the remaining bit of the line again. The undoes often span saves, which doesn't make sense to me. You would think that when you save, make a change and then undo, you would go back no further than the save point. However, that's not the case. These minor inconveniences happens so often that I would probably prefer having to undo one character at a time, Emacs style. Anyone know if that is somehow possible?

The less common scenario is one that's even more inconvenient and seems more like an actual bug. Sometimes I make some changes to my code. Run it in debug mode and go play with the interface (normally in a browser). Then 10-20 minutes later, for instance, I hit a breakpoint while I'm typing somewhere (say writing an email), Eclipse jumps up and steals focus and I accidentally type something in my code. Now, when I undo, Eclipse often decides to not just undo the change I just made, but also some of the changes I made 10-20 minutes (sometimes even longer) ago all in one go. Surely this must have happened to someone else? It seems to me that the only "safe" thing to do is revert to the last save, as you might not know exactly what you've changed accidentally, and the undo takes you back before the last save losing some random code (and the accidental entry might have deleted code as well, if something was selected when Eclipse stole focus).

So, that was a rather long rant. I'd just like to hear if anything else has experienced this, finds it frustrating or even have a solution :)


I just created a new Java class:

public class TestUndo {
    public static void main(String[] args) {

Then put

System.out.println("Hello world");<enter>

at the position where | is - and without making any typo's or other mistakes, pressing ctrl-z removes the following in order:

  • removes first the ;
  • then the contents of the brackets "Hello world"
  • then ()
  • then println
  • then . but selects out
  • then System.out

This seems quite logical as it groups by syntax groups, and I'm back to where I started. Note, this is all in Eclipse 3.7.1; YMMV.

However, if I make a typo at any point in typing System.out.println("Hello world"); or use any cursor keys or backspace, that'll reset the undo state, and later when repeatedly pressing ctrl-z, you'll jump back to each typo - so it's possible that the erratic undo behaviour is caused by moving around whilst typing.

There is a bug listed on the Eclipse bugs mailing that describes this "broken" behaviour: https://bugs.eclipse.org/bugs/show_bug.cgi?id=49553

and a patch was suggested; however, it's marked as "assigned" but never made it into any released version, and that was in 2006 so it's unlikely this will change any time soon.

An alternative to using ctrl-z a lot is use Eclipse's "Local History" feature - right click on the file and "compare with" -> "local history" - then you can have a visual diff of recent changes you've made to the file.

(As a final "fix", you say you're after Emacs' kill-ring functionality in Eclipse - http://www.mulgasoft.com/ seems to offer some Eclipse extensions for making it behave more Emacs'y - so you could try that; personally, I just use Emacs with CEDET!)

  • I realise the explanation of the first problem was wrong, and I've now updated it. – Svend Hansen Oct 22 '12 at 15:00

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.