Undo In Region

Over at the Emacs subreddit, tms9918 says he sometimes changes a line, make changes in other parts of the file, and then wants to restore that first line. He was asking if there was anyway of doing that. There is, of course, as I’ve written before. The thing is, tms9918’s post was full of comments expressing wonder at how the commenter didn’t already know this. That led me to believe that a reprise of the issue was called for, especially since it’s so useful.

It is, after all, a situation that comes up often: you make a series of changes and then find that you want to undo one of the earlier changes. It’s extraordinarily easy to do. All you need do is highlight the region you want to restore and undo will apply only in that region. It works out-of-the-box if you’re using the default Emacs undo system. If you’re using undo-tree, you have to set undo-tree-enable-undo-in-region to t in your configuration.

You don’t need this all the time, of course, but when you do it’s easy to remember how to do it. There’s not special key binding to know or lookup. You simply highlight the region you want to restore and invoke undo in the usual way. Try it out; you’ll be delighted.

This entry was posted in General and tagged . Bookmark the permalink.