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