1 @c This is part of the Emacs manual.
2 @c Copyright (C) 1985-1987, 1993-1995, 1997, 2001-2015 Free Software
4 @c See file emacs.texi for copying conditions.
6 @chapter Characters, Keys and Commands
8 This chapter explains the character sets used by Emacs for input
9 commands, and the fundamental concepts of @dfn{keys} and
10 @dfn{commands}, whereby Emacs interprets your keyboard and mouse
19 @section Kinds of User Input
20 @cindex input with the keyboard
21 @cindex keyboard input
22 @cindex character set (keyboard)
23 @cindex @acronym{ASCII}
27 GNU Emacs is primarily designed for use with the keyboard. While it
28 is possible to use the mouse to issue editing commands through the
29 menu bar and tool bar, that is not as efficient as using the keyboard.
30 Therefore, this manual mainly documents how to edit with the keyboard.
32 @cindex control character
33 Keyboard input into Emacs is based on a heavily-extended version of
34 @acronym{ASCII}. Simple characters, like @samp{a}, @samp{B},
35 @samp{3}, @samp{=}, and the space character (denoted as @key{SPC}),
36 are entered by typing the corresponding key. @dfn{Control
37 characters}, such as @key{RET}, @key{TAB}, @key{DEL}, @key{ESC},
38 @key{F1}, @key{Home}, and @key{LEFT}, are also entered this way, as
39 are certain characters found on non-English keyboards
40 (@pxref{International}).
47 Emacs also recognizes control characters that are entered using
48 @dfn{modifier keys}. Two commonly-used modifier keys are
49 @key{Control} (usually labeled @key{Ctrl}), and @key{META} (usually
50 labeled @key{Alt})@footnote{We refer to @key{Alt} as @key{META} for
51 historical reasons.}. For example, @kbd{Control-a} is entered by
52 holding down the @key{Ctrl} key while pressing @kbd{a}; we will refer
53 to this as @kbd{C-a} for short. Similarly @kbd{@key{META}-a}, or @kbd{M-a}
54 for short, is entered by holding down the @key{Alt} key and pressing
55 @kbd{a}. Modifier keys can also be applied to non-alphanumerical
56 characters, e.g., @kbd{C-@key{F1}} or @kbd{M-@key{LEFT}}.
58 @cindex @key{ESC} replacing @key{META} key
59 You can also type Meta characters using two-character sequences
60 starting with @key{ESC}. Thus, you can enter @kbd{M-a} by typing
61 @kbd{@key{ESC} a}. You can enter @kbd{C-M-a} by typing @kbd{@key{ESC}
62 C-a}. Unlike @key{META}, @key{ESC} is entered as a separate
63 character. You don't hold down @key{ESC} while typing the next
64 character; instead, press @key{ESC} and release it, then enter the
65 next character. This feature is useful on certain text terminals
66 where the @key{META} key does not function reliably.
68 @cindex keys stolen by window manager
69 @cindex window manager, keys stolen by
70 On graphical displays, the window manager might block some keyboard
71 inputs, including @kbd{M-@key{TAB}}, @kbd{M-@key{SPC}}, @kbd{C-M-d}
72 and @kbd{C-M-l}. If you have this problem, you can either customize
73 your window manager to not block those keys, or rebind the
74 affected Emacs commands (@pxref{Customization}).
77 Simple characters and control characters, as well as certain
78 non-keyboard inputs such as mouse clicks, are collectively referred to
79 as @dfn{input events}. For details about how Emacs internally handles
80 input events, see @ref{Input Events,,, elisp, The Emacs Lisp Reference
86 Some Emacs commands are invoked by just one input event; for
87 example, @kbd{C-f} moves forward one character in the buffer. Other
88 commands take two or more input events to invoke, such as @kbd{C-x
89 C-f} and @kbd{C-x 4 C-f}.
95 A @dfn{key sequence}, or @dfn{key} for short, is a sequence of one
96 or more input events that is meaningful as a unit. If a key sequence
97 invokes a command, we call it a @dfn{complete key}; for example,
98 @kbd{C-f}, @kbd{C-x C-f} and @kbd{C-x 4 C-f} are all complete keys.
99 If a key sequence isn't long enough to invoke a command, we call it a
100 @dfn{prefix key}; from the preceding example, we see that @kbd{C-x}
101 and @kbd{C-x 4} are prefix keys. Every key sequence is either a
102 complete key or a prefix key.
104 A prefix key combines with the following input event to make a
105 longer key sequence. For example, @kbd{C-x} is a prefix key, so
106 typing @kbd{C-x} alone does not invoke a command; instead, Emacs waits
107 for further input (if you pause for longer than a second, it echoes
108 the @kbd{C-x} key to prompt for that input; @pxref{Echo Area}).
109 @kbd{C-x} combines with the next input event to make a two-event key
110 sequence, which could itself be a prefix key (such as @kbd{C-x 4}), or
111 a complete key (such as @kbd{C-x C-f}). There is no limit to the
112 length of key sequences, but in practice they are seldom longer than
113 three or four input events.
115 You can't add input events onto a complete key. For example,
116 because @kbd{C-f} is a complete key, the two-event sequence @kbd{C-f
117 C-k} is two key sequences, not one.
119 By default, the prefix keys in Emacs are @kbd{C-c}, @kbd{C-h},
120 @kbd{C-x}, @kbd{C-x @key{RET}}, @kbd{C-x @@}, @kbd{C-x a}, @kbd{C-x
121 n}, @kbd{C-x r}, @kbd{C-x v}, @kbd{C-x 4}, @kbd{C-x 5}, @kbd{C-x 6},
122 @key{ESC}, @kbd{M-g}, and @kbd{M-o}. (@key{F1} and @key{F2} are
123 aliases for @kbd{C-h} and @kbd{C-x 6}.) This list is not cast in
124 stone; if you customize Emacs, you can make new prefix keys. You
125 could even eliminate some of the standard ones, though this is not
126 recommended for most users; for example, if you remove the prefix
127 definition of @kbd{C-x 4}, then @kbd{C-x 4 C-f} becomes an invalid key
128 sequence. @xref{Key Bindings}.
130 Typing the help character (@kbd{C-h} or @key{F1}) after a prefix key
131 displays a list of the commands starting with that prefix. The sole
132 exception to this rule is @key{ESC}: @kbd{@key{ESC} C-h} is equivalent
133 to @kbd{C-M-h}, which does something else entirely. You can, however,
134 use @key{F1} to display a list of commands starting with @key{ESC}.
137 @section Keys and Commands
141 This manual is full of passages that tell you what particular keys
142 do. But Emacs does not assign meanings to keys directly. Instead,
143 Emacs assigns meanings to named @dfn{commands}, and then gives keys
144 their meanings by @dfn{binding} them to commands.
146 Every command has a name chosen by a programmer. The name is
147 usually made of a few English words separated by dashes; for example,
148 @code{next-line} or @code{forward-word}. Internally, each command is
149 a special type of Lisp @dfn{function}, and the actions associated with
150 the command are performed by running the function. @xref{What Is a
151 Function,, What Is a Function, elisp, The Emacs Lisp Reference
154 The bindings between keys and commands are recorded in tables called
155 @dfn{keymaps}. @xref{Keymaps}.
157 When we say that ``@kbd{C-n} moves down vertically one line'' we are
158 glossing over a subtle distinction that is irrelevant in ordinary use,
159 but vital for Emacs customization. The command @code{next-line} does
160 a vertical move downward. @kbd{C-n} has this effect @emph{because} it
161 is bound to @code{next-line}. If you rebind @kbd{C-n} to the command
162 @code{forward-word}, @kbd{C-n} will move forward one word instead.
164 In this manual, we will often speak of keys like @kbd{C-n} as
165 commands, even though strictly speaking the key is bound to a command.
166 Usually we state the name of the command which really does the work in
167 parentheses after mentioning the key that runs it. For example, we
168 will say that ``The command @kbd{C-n} (@code{next-line}) moves point
169 vertically down'', meaning that the command @code{next-line} moves
170 vertically down, and the key @kbd{C-n} is normally bound to it.
172 Since we are discussing customization, we should tell you about
173 @dfn{variables}. Often the description of a command will say, ``To
174 change this, set the variable @code{mumble-foo}.'' A variable is a
175 name used to store a value. Most of the variables documented in this
176 manual are meant for customization: some command or other part of
177 Emacs examines the variable and behaves differently according to the
178 value that you set. You can ignore the information about variables
179 until you are interested in customizing them. Then read the basic
180 information on variables (@pxref{Variables}) and the information about
181 specific variables will make sense.