Kinds of User Input
===================

GNU Emacs is designed for use with keyboard commands because that is the most efficient way to edit.  You can do editing with the mouse, as in other editors, and you can give commands with the menu bar and tool bar, and scroll with the scroll bar.  But if you keep on editing that way, you won't get the benefits of Emacs.  Therefore, this manual documents primarily how to edit with the keyboard.  You can force yourself to practice using the keyboard by using the shell command emacs -nw to start Emacs, so that the mouse won't work.

Emacs uses an extension of the ASCII character set for keyboard input; it also accepts non-character input events including function keys and mouse button actions.

ASCII consists of 128 character codes.  Some of these codes are assigned graphic symbols such as a and =; the rest are control characters, such as Control-a (usually written C-a for short).  C-a gets its name from the fact that you type it by holding down the CTRL key while pressing a.

Some ASCII control characters have special names, and most terminals have special keys you can type them with: for example, RET, TAB, DEL and ESC.  The space character is usually known as SPC, even though strictly speaking it is a graphic character that is blank.

Emacs extends the ASCII character set with thousands more printing characters (see International), additional control characters, and a few more modifiers that can be combined with any character.

On ASCII terminals, there are only 32 possible control characters. These are the control variants of letters and @[]\^_.  In addition, the shift key is meaningless with control characters: C-a and C-A are the same character, and Emacs cannot distinguish them.

The Emacs character set has room for control variants of all printing characters, and distinguishes C-A from C-a. Graphical terminals make it possible to enter all these characters. For example, C-- (that's Control-Minus) and C-5 are meaningful Emacs commands on a graphical terminal.

Another Emacs character-set extension is additional modifier bits. Only one modifier bit is commonly used; it is called Meta.  Every character has a Meta variant; examples include Meta-a (normally written M-a, for short), M-A (different from M-a, but they are normally equivalent in Emacs), M-RET, and M-C-a.  That last means a with both the CTRL and META modifiers.  We usually write it as C-M-a rather than M-C-a, for reasons of tradition.

Some terminals have a META key, and allow you to type Meta characters by holding this key down.  Thus, you can type Meta-a by holding down META and pressing a.  The META key works much like the SHIFT key.  In fact, this key is more often labeled ALT or EDIT, instead of META; on a Sun keyboard, it may have a diamond on it.

If there is no META key, you can still type Meta characters using two-character sequences starting with ESC.  Thus, you can enter M-a by typing ESC a.  You can enter C-M-a by typing ESC C-a.  Unlike META, which modifies other characters, ESC is a separate character.  You don't hold down ESC while typing the next character; instead, you press it and release it, then you enter the next character. ESC is allowed on terminals with META keys, too, in case you have formed a habit of using it.

Emacs defines several other modifier keys that can be applied to any input character.  These are called SUPER, HYPER and ALT.  We write s-, H- and A- to say that a character uses these modifiers.  Thus, s-H-C-x is short for Super-Hyper-Control-x.  Not all graphical terminals actually provide keys for these modifier flags---in fact, many terminals have a key labeled ALT which is really a META key.  The standard key bindings of Emacs do not include any characters with these modifiers.  But you can assign them meanings of your own by customizing Emacs.

If your keyboard lacks one of these modifier keys, you can enter it using C-x @: C-x @ h adds the ``hyper'' flag to the next character, C-x @ s adds the ``super'' flag, and C-x @ a adds the ``alt'' flag.  For instance, C-x @ h C-a is a way to enter Hyper-Control-a.  (Unfortunately there is no way to add two modifiers by using C-x @ twice for the same character, because the first one goes to work on the C-x.)

Keyboard input includes keyboard keys that are not characters at all, such as function keys and arrow keys.  Mouse buttons are also not characters.  However, you can modify these events with the modifier keys CTRL, META, SUPER, HYPER and ALT, just like keyboard characters.

Input characters and non-character inputs are collectively called input events.  See Input Events (The Emacs Lisp Reference Manual), for the full Lisp-level details.  If you are not doing Lisp programming, but simply want to redefine the meaning of some characters or non-character events, see Customization.

ASCII terminals cannot really send anything to the computer except ASCII characters.  These terminals use a sequence of characters to represent each function key.  But that is invisible to the Emacs user, because the keyboard input routines catch these special sequences and convert them to function key events before any other part of Emacs gets to see them.

Keys
====

A key sequence (key, for short) is a sequence of input events that is meaningful as a unit---a ``single command.''  Some Emacs command sequences are invoked by just one character or one event; for example, just C-f moves forward one character in the buffer.  But Emacs also has commands that take two or more events to invoke.

If a sequence of events is enough to invoke a command, it is a complete key.  Examples of complete keys include C-a, X, RET, NEXT (a function key), DOWN (an arrow key), C-x C-f, and C-x 4 C-f.  If it isn't long enough to be complete, we call it a prefix key.  The above examples show that C-x and C-x 4 are prefix keys.  Every key sequence is either a complete key or a prefix key.

Most single characters constitute complete keys in the standard Emacs command bindings.  A few of them are prefix keys.  A prefix key combines with the following input event to make a longer key sequence, which may itself be complete or a prefix.  For example, C-x is a prefix key, so C-x and the next input event combine to make a two-event key sequence.  Most of these key sequences are complete keys, including C-x C-f and C-x b.  A few, such as C-x 4 and C-x r, are themselves prefix keys that lead to three-event key sequences.  There's no limit to the length of a key sequence, but in practice people rarely use sequences longer than four events.

You can't add input events onto a complete key.  For example, the two-event sequence C-f C-k is not a key, because the C-f is a complete key in itself.  It's impossible to give C-f C-k an independent meaning as a command.  C-f C-k is two key sequences, not one.

All told, the prefix keys in Emacs are C-c, C-h, C-x, C-x RET, C-x @, C-x a, C-x n, C-x r, C-x v, C-x 4, C-x 5, C-x 6, ESC, M-g, and M-o.  (F1 and F2 are aliases for C-h and C-x 6.)  This list is not cast in stone; it describes the standard key bindings.  If you customize Emacs, you can make new prefix keys, or eliminate some of the standard ones (not recommended for most users).  See Key Bindings.

If you make or eliminate prefix keys, that changes the set of possible key sequences.  For example, if you redefine C-f as a prefix, C-f C-k automatically becomes a key (complete, unless you define that too as a prefix).  Conversely, if you remove the prefix definition of C-x 4, then C-x 4 f and C-x 4 ANYTHING are no longer keys.

Typing the help character (C-h or F1) after a prefix key displays a list of the commands starting with that prefix.  There are a few prefix keys after which C-h does not work---for historical reasons, they define other meanings for C-h which are painful to change.  F1 works after all prefix keys.

Keys and Commands
=================

This manual is full of passages that tell you what particular keys do.  But Emacs does not assign meanings to keys directly.  Instead, Emacs assigns meanings to named commands, and then gives keys their meanings by binding them to commands.

Every command has a name chosen by a programmer.  The name is usually made of a few English words separated by dashes; for example, next-line or forward-word.  A command also has a function definition which is a Lisp program; this is how the command does its work.  In Emacs Lisp, a command is a Lisp function with special options to read arguments and for interactive use.  For more information on commands and functions, see What Is a Function (The Emacs Lisp Reference Manual).  (The definition here is simplified slightly.)

The bindings between keys and commands are recorded in tables called keymaps.  See Keymaps.

When we say that ``C-n moves down vertically one line'' we are glossing over a subtle distinction that is irrelevant in ordinary use, but vital for Emacs customization.  The command next-line does a vertical move downward.  C-n has this effect because it is bound to next-line.  If you rebind C-n to the command forward-word, C-n will move forward one word instead. Rebinding keys is an important method of customization.

In the rest of this manual, we usually ignore this distinction to keep things simple.  We will often speak of keys like C-n as commands, even though strictly speaking the key is bound to a command. Usually we state the name of the command which really does the work in parentheses after mentioning the key that runs it.  For example, we will say that ``The command C-n (next-line) moves point vertically down,'' meaning that the command next-line moves vertically down, and the key C-n is normally bound to it.

Since we are discussing customization, we should tell you about variables.  Often the description of a command will say, ``To change this, set the variable mumble-foo.''  A variable is a name used to store a value.  Most of the variables documented in this manual are meant for customization: some command or other part of Emacs examines the variable and behaves differently according to the value that you set.  You can ignore the information about variables until you are interested in customizing them.  Then read the basic information on variables (see Variables) and the information about specific variables will make sense.

Character Set for Text
======================

Text in Emacs buffers is a sequence of characters.  In the simplest case, these are ASCII characters, each stored in one 8-bit byte.  Both ASCII control characters (octal codes 000 through 037, and 0177) and ASCII printing characters (codes 040 through 0176) are allowed.  The other modifier flags used in keyboard input, such as Meta, are not allowed in buffers.

Non-ASCII printing characters can also appear in buffers, when multibyte characters are enabled.  They have character codes starting at 256, octal 0400, and each one is represented as a sequence of two or more bytes.  See International.  Single-byte characters with codes 128 through 255 can also appear in multibyte buffers. However, non-ASCII control characters cannot appear in a buffer.

Some ASCII control characters serve special purposes in text, and have special names.  For example, the newline character (octal code 012) is used in the buffer to end a line, and the tab character (octal code 011) is used for indenting to the next tab stop column (normally every 8 columns).  See Text Display.

If you disable multibyte characters, then you can use only one alphabet of non-ASCII characters, which all fit in one byte. They use octal codes 0200 through 0377.  See Unibyte Mode.