How To Exit Emacs?
Spending the rest of your life in Emacs is a feature, not a bug.
Above: My empty i3 window manager, after I quit Emacs
tl;dr (take 2)
This is the magic key combination to exit Emacs:
Which reads as
I.e., press the
Control key with your left pinky, hold it pressed,
x (while still holding the
Control key), press
You are back to normal life.
In Emacs, key bindings are called
keybindings because we like things
to be plain. Some people in other possible worlds called them
shortcuts but that is a very narrow view of what a keybinding is,
since Emacs keybindings have a personnality of their own and can be a
bit long sometimes.
The first time you encounter
Control-x, you think: "Aha… so the
x stands for eXiting!". Wrong.
The "x" stands for eXecuting.
Let's tell a bit more about keybindings.
Emacs keybindings are stored in
keymap is a variable containing a list of associations between
The list of all keybindings starting with
Control-x is stored in a
dedicated variable called
You can see this list with
C-h v ctl-x-map RET : this will open a new
buffer and display the value of the keymap.
You can also display the list of commands starting with the
prefix bit hitting
C-x C-h (yes, the
h stands for help).
Do it now, and enjoy the beautiful view!
In this buffer, you can follow links by hitting
those are links to the descriptions of commands associated with the
listed keybindings—or to sub keymaps.
For example, the buffer will let you learn that
C-x C-c is bound to
save-buffers-kill-terminal. Yes, this is the name of the command
you call to "exit Emacs", as people call it sometimes.
C-x C-k is bound to
kmacro-keymap, which is not a command, but
If you want to know more about this other keymap, hit
C-x C-k C-h.
(And yes, the "h" in
C-h stands for Help.)
Of course, since keymaps are just variables, you can change them at will. I recommend not to change the default keybindings: Emacs is not only a text editor, it's a shared culture, and sticking to the default keybindings helps the community celebrate the same commands together.
x = ?
Happiness is nothing more than good health and a bad memory. -- Albert Schweitzer
Control-x keymap is the most important keymap in Emacs: main
commands are called from this keymap.
Control-c keymap is the second most important one. Emacs modes
use it to associate keybindings with the new commands they define.
.emacs.el file late at night, amont binary dreams and
computer fairies, you sometimes encounter a pattern:
C-c x, where
x is a letter or a digit. This pattern is reserved for the user:
this is where you, the user, are required to place your keybindings.
No decent Emacs mode will ever use this pattern for its keybindings.
C-c C-... is used by all modes: but this is
C-c ... — please note the difference.
So what does this
x stand for?
If you know Emacs, you know a bit of
M-x: hitting this puts the
cursor in the
minibuffer, and prompts you for the name of a command.
The name of the command associated with
execute-extended-command, so my guess is that
x stands for
Which makes sense, right?
I also guess the
Control-x stands for "execute", since this
is the main map to execute stuff in Emacs. At least I want to
C-c stands for in
If you use
C-c in shells, you know the answer. And of course Wikipedia comes to the rescue:
As many keyboards and computer terminals once directly generated ASCII code, the choice of control-C overlapped with the ASCII end-of-text character. This character has a numerical value of three, as "C" is the third letter of the alphabet. It was chosen to cause an interrupt as it is otherwise unlikely to be part of a program's interactive interface. Many other control codes, such as control-D for the end-of-transmission character, do not generate signals and are occasionally used to control a program.
See? Now you know why
C-x C-c exits Emacs.
But remember: you don't really want to exit Emacs.
To comment this blog post, you can send an email to the public mailing list ~email@example.com