1 @c This is part of the Emacs manual.
2 @c Copyright (C) 1985, 1986, 1987, 1993, 1994, 1995, 1997, 2001, 2002,
3 @c 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
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
18 @node User Input, Keys, Screen, Top
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}
26 @cindex control characters
28 GNU Emacs is primarily designed for use with the keyboard. While it
29 is possible to use the mouse to issue editing commands through the
30 menu bar and tool bar, that is not as efficient as using the keyboard.
31 Therefore, this manual mainly documents how to edit with the keyboard.
33 Keyboard input into Emacs is based on a heavily-extended version of
34 @acronym{ASCII}. The simplest characters that you can input into
35 Emacs correspond to graphic symbols such as @samp{a}, @samp{B},
36 @samp{3}, @samp{=}, the space character (conventionally denoted as
37 @key{SPC}), and so on. Entering these using the keyboard is
38 straightforward. Certain characters found on non-English keyboards
39 also fall into this category (@pxref{International}).
41 In addition to these simple characters, Emacs recognizes
42 @dfn{control characters} such as @key{RET}, @key{TAB}, @key{DEL},
43 @key{ESC}, @key{F1}, @key{Home}, @key{left}, etc. Most keyboards have
44 special keys for entering these.
51 Emacs also recognizes control characters that are entered using
52 @dfn{modifier keys}. Two commonly-used modifier keys are
53 @key{Control} (which is usually labelled as @key{Ctrl}), and
54 @key{Meta} (which is usually labeled as @key{Alt})@footnote{We refer
55 to @key{Alt} as @key{Meta} for historical reasons.}. For example,
56 @kbd{Control-a} is entered by holding down the @key{Ctrl} key while
57 pressing @kbd{a}; we will refer to this as @kbd{C-a} for short.
58 Similarly @kbd{Meta-a}, or @kbd{M-a} for short, is entered by holding
59 down the @key{Alt} key and pressing @kbd{a}.
61 @cindex @key{ESC} replacing @key{Meta} key
62 You can also type Meta characters using two-character sequences
63 starting with @key{ESC}. Thus, you can enter @kbd{M-a} by typing
64 @kbd{@key{ESC} a}. You can enter @kbd{C-M-a} by typing @kbd{@key{ESC}
65 C-a}. Unlike @key{Meta}, @key{ESC} is entered as a separate
66 character. You don't hold down @key{ESC} while typing the next
67 character; instead, press @key{ESC} and release it, then enter the
68 next character. This feature is useful on certain text-only terminals
69 where the @key{Meta} key does not function reliably.
71 Modifier keys can apply not only to alphanumerical characters, but
72 also to special input characters, such as the arrow keys and mouse
76 @xref{Input Events,,, elisp, The Emacs Lisp Reference Manual}, for
77 the full Lisp-level details about keyboard and mouse input, which are
78 collectively referred to as @dfn{input events}. If you are not doing
79 Lisp programming, but simply want to redefine the meaning of some
80 characters or non-character events, see @ref{Customization}.
82 @cindex keys stolen by window manager
83 @cindex window manager, keys stolen by
84 On graphical displays, the window manager is likely to block the
85 character @kbd{M-@key{TAB}} before Emacs can see it. It may also
86 block @kbd{M-@key{SPC}}, @kbd{C-M-d} and @kbd{C-M-l}. If you have
87 these problems, we recommend that you customize your window manager to
88 turn off those commands, or put them on key combinations that Emacs
91 @node Keys, Commands, User Input, Top
94 Some Emacs commands are invoked by just one input event; for
95 example, @kbd{C-f} moves forward one character in the buffer. But
96 Emacs also has commands that take two or more input events to invoke,
97 such as @kbd{C-x C-f} and @kbd{C-x 4 C-f}.
103 A @dfn{key sequence}, or @dfn{key} for short, is a sequence of one
104 or more input events that is meaningful as a unit. If a key sequence
105 invokes a command, we call it a @dfn{complete key}; for example,
106 @kbd{C-f}, @kbd{C-x C-f} and @kbd{C-x 4 C-f} are all complete keys.
107 If a key sequence isn't long enough to invoke a command, we call it a
108 @dfn{prefix key}; from the preceding example, we see that @kbd{C-x}
109 and @kbd{C-x 4} are prefix keys. Every key is either a complete key
112 A prefix key combines with the following input event to make a
113 longer key sequence, which may itself be complete or a prefix. For
114 example, @kbd{C-x} is a prefix key, so @kbd{C-x} and the next input
115 event combine to make a two-event key sequence. This two-event key
116 sequence could itself be a prefix key (such as @kbd{C-x 4}), or a
117 complete key (such as @kbd{C-x C-f}). There is no limit to the length
118 of a key sequence, but in practice people rarely use sequences longer
119 than three or four input events.
121 You can't add input events onto a complete key. For example, the
122 two-event sequence @kbd{C-f C-k} is not a key, because the @kbd{C-f}
123 is a complete key in itself, so @kbd{C-f C-k} cannot have an
124 independent meaning as a command. @kbd{C-f C-k} is two key sequences,
127 By default, the prefix keys in Emacs are @kbd{C-c}, @kbd{C-h},
128 @kbd{C-x}, @kbd{C-x @key{RET}}, @kbd{C-x @@}, @kbd{C-x a}, @kbd{C-x
129 n}, @kbd{C-x r}, @kbd{C-x v}, @kbd{C-x 4}, @kbd{C-x 5}, @kbd{C-x 6},
130 @key{ESC}, @kbd{M-g}, and @kbd{M-o}. (@key{F1} and @key{F2} are
131 aliases for @kbd{C-h} and @kbd{C-x 6}.) This list is not cast in
132 stone; if you customize Emacs, you can make new prefix keys. You
133 could even eliminate some of the standard ones, though this is not
134 recommended for most users; for example, if you remove the prefix
135 definition of @kbd{C-x 4}, then @kbd{C-x 4 @var{anything}} would
136 become an invalid key sequence. @xref{Key Bindings}.
138 Typing the help character (@kbd{C-h} or @key{F1}) after a prefix key
139 displays a list of the commands starting with that prefix. The sole
140 exception to this rule is @key{ESC}: @kbd{@key{ESC}C-h} is equivalent
141 to @kbd{C-M-h}, which does something else entirely. You can, however,
142 use @key{F1} to displays a list of the commands starting with
145 @node Commands, Entering Emacs, Keys, Top
146 @section Keys and Commands
150 @cindex function definition
151 This manual is full of passages that tell you what particular keys
152 do. But Emacs does not assign meanings to keys directly. Instead,
153 Emacs assigns meanings to named @dfn{commands}, and then gives keys
154 their meanings by @dfn{binding} them to commands.
156 Every command has a name chosen by a programmer. The name is
157 usually made of a few English words separated by dashes; for example,
158 @code{next-line} or @code{forward-word}. A command also has a
159 @dfn{function definition} which is a Lisp program; this is how the
160 command does its work. In Emacs Lisp, a command is a Lisp function
161 with special properties that make it suitable for interactive use.
162 For more information on commands and functions, see @ref{What Is a
163 Function,, What Is a Function, elisp, The Emacs Lisp Reference
166 The bindings between keys and commands are recorded in tables called
167 @dfn{keymaps}. @xref{Keymaps}.
169 When we say that ``@kbd{C-n} moves down vertically one line'' we are
170 glossing over a subtle distinction that is irrelevant in ordinary use,
171 but vital for Emacs customization. The command @code{next-line} does
172 a vertical move downward. @kbd{C-n} has this effect @emph{because} it
173 is bound to @code{next-line}. If you rebind @kbd{C-n} to the command
174 @code{forward-word}, @kbd{C-n} will move forward one word instead.
176 In this manual, we will often speak of keys like @kbd{C-n} as
177 commands, even though strictly speaking the key is bound to a command.
178 Usually we state the name of the command which really does the work in
179 parentheses after mentioning the key that runs it. For example, we
180 will say that ``The command @kbd{C-n} (@code{next-line}) moves point
181 vertically down,'' meaning that the command @code{next-line} moves
182 vertically down, and the key @kbd{C-n} is normally bound to it.
184 Since we are discussing customization, we should tell you about
185 @dfn{variables}. Often the description of a command will say, ``To
186 change this, set the variable @code{mumble-foo}.'' A variable is a
187 name used to store a value. Most of the variables documented in this
188 manual are meant for customization: some command or other part of
189 Emacs examines the variable and behaves differently according to the
190 value that you set. You can ignore the information about variables
191 until you are interested in customizing them. Then read the basic
192 information on variables (@pxref{Variables}) and the information about
193 specific variables will make sense.
200 arch-tag: 9be43eef-d1f4-4d03-a916-c741ea713a45