Stopping Commands and Undoing Changes

Sometimes you start a command by accident or change your mind about it. Don’t worry: with Emacs, you can quit in the middle or undo it.

Stopping Commands

When you want to stop any command that’s in progress, press C-g. The word Quit appears in the command area.

Undoing Changes

What happens if you make a mistake while you’re editing? You can undo your changes by pressing C-x u, C-_, or C-/ (for undo) or selecting Undo from the Edit menu. By typing C-x u repeatedly, you can gradually work your way back to a point before your mistake. Although the undo command is very powerful, saving your file frequently, if not compulsively, is nevertheless a good idea. We usually save a file whenever we stop typing—even if only for a few seconds. Train your fingers to press C-x C-s whenever you pause; it’s a good habit to form.

What if you’d like to redo a command after you type undo? There is no formal redo command, but you can use undo in the following way. Just move the cursor in any direction, and type C-x u again. Emacs redoes the last command you undid. You can repeat it to redo previous undos.

Although undo is an important command, it can be slow if you want to undo a large number of changes. Table 2-7 summarizes three methods for undoing changes and circumstances in which you might want to use them.

Table 3-7. Methods for Undoing Changes

If you

Use this command

Don’t like the recent changes you’ve made and want to undo them one by one

Get Learning GNU Emacs, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.