Emacs – Get Me out of Here!
Topic: Quitting or exiting stuff in Emacs
Have you ever had that feeling you cannot get out of something in Emacs? And hitting C-g
over and over again does nothing? It is sort of like trying to exit Vim
except you know you are in Emacs (not really!)
*Important get-me-out commands
C-g
quits a partially typed command or one that is running
The problem comes in with "recursive edits".
A recursive edit is one performed within an invoked Emacs command.
Entering a recursive edit allows one to temporarily pause the current command and perform other edits, after which one can exit the recursive edit and return to the original command.
It is much like multi-tasking.
For example, M-x query-replace
C-r
enters a recursive edit
C-M-c
will allow you to exit the recursive edit and return to query-replace
This is an example This was an example This is an example
Note: that recursive edits are indicated in the mode line: square brackets are placed around mode names.
Sometimes one enters a recursive edit accidentally and cannot seem to exit using C-g
C-]
aborts the innermost level of a recursive edit, i.e. it exits the edit and quits the unfinished command
I say "innermost level" because there can be multiple levels of recursive edits.
M-x top-level
aborts all levels of recursive edits
ESC ESC ESC
offers a broader "reset" functionality that C-g
. It both quits and aborts, thus providing a wider range of exit and clean-up functionalities
- It cancels a prefix argument
- Clears a selected region
- Clears echo area
- Exits the minibuffer
- Exits a recursive edit
- Can remove multiple split windows
Note: ESC ESC ESC
cannot stop a running command
Note: While these commands are incredibly useful, they might seem a little overwhelming if one is a new user.
As with much of Emacs, the key is practice!
Ergo, to get out try these commands:
C-g
C-]
(if you see recursion in modeline)
ESC ESC ESC
If all this fails: "If you have tears, prepare to shed them now…"