Emacs is the extensible, customizable, self-documenting real-time display editor. This Info file describes how to edit with Emacs and some of how to customize it; it corresponds to GNU Emacs version 22.1.
For information on extending Emacs, see Emacs Lisp.
Indexes (each index contains a large menu)
Important General Concepts
Fundamental Editing Commands
Important Text-Changing Commands
Major Structures of Emacs
Advanced Features
Recovery from Problems
--- The Detailed Node Listing --- ---------------------------------
Here are some other nodes which are really inferiors of the ones already listed, mentioned here so you can get to them in one step:
The Organization of the Screen
Basic Editing Commands
The Minibuffer
Completion
Help
The Mark and the Region
Killing and Moving Text
Yanking
Registers
Controlling the Display
Searching and Replacement
Incremental Search
Replacement Commands
Commands for Fixing Typos
Keyboard Macros
File Handling
Saving Files
Backup Files
Auto-Saving: Protection Against Disasters
Version Control
Using Multiple Buffers
Multiple Windows
Frames and Graphical Displays
International Character Set Support
Major Modes
Indentation
Commands for Human Languages
Filling Text
Outline Mode
TeX Mode
Editing Formatted Text
Editing Text-based Tables
Editing Programs
Top-Level Definitions, or Defuns
Indentation for Programs
Commands for Editing with Parentheses
Manipulating Comments
Documentation Lookup
C and Related Modes
Compiling and Testing Programs
Running Debuggers Under Emacs
Maintaining Large Programs
Tags Tables
Abbrevs
Editing Pictures
Sending Mail
Reading Mail with Rmail
Dired, the Directory Editor
The Calendar and the Diary
Movement in the Calendar
Conversion To and From Other Calendars
The Diary
Gnus
Running Shell Commands from Emacs
Using Emacs as a Server
Printing Hard Copies
Hyperlinking and Navigation Features
Customization
Variables
Customizing Key Bindings
The Init File, ~/.emacs
Dealing with Emacs Trouble
Reporting Bugs
Command Line Arguments for Emacs Invocation
Environment Variables
X Options and Resources
Emacs and Mac OS
Emacs and Microsoft Windows/MS-DOS
GNU Emacs is free software; this means that everyone is free to use it and free to redistribute it on certain conditions. GNU Emacs is not in the public domain; it is copyrighted and there are restrictions on its distribution, but these restrictions are designed to permit everything that a good cooperating citizen would want to do. What is not allowed is to try to prevent others from further sharing any version of GNU Emacs that they might get from you. The precise conditions are found in the GNU General Public License that comes with Emacs and also appears in this manual1. See Copying.
One way to get a copy of GNU Emacs is from someone else who has it. You need not ask for our permission to do so, or tell any one else; just copy it. If you have access to the Internet, you can get the latest distribution version of GNU Emacs by anonymous FTP; see http://www.gnu.org/software/emacs on our website for more information.
You may also receive GNU Emacs when you buy a computer. Computer manufacturers are free to distribute copies on the same terms that apply to everyone else. These terms require them to give you the full sources, including whatever changes they may have made, and to permit you to redistribute the GNU Emacs received from them under the usual terms of the General Public License. In other words, the program must be free for you when you get it, not just free for the manufacturer.
You can also order copies of GNU Emacs from the Free Software Foundation. This is a convenient and reliable way to get a copy; it is also a good way to help fund our work. We also sell hardcopy versions of this manual and An Introduction to Programming in Emacs Lisp, by Robert J. Chassell. You can find an order form on our web site at http://www.gnu.org/order/order.html. For further information, write to
Free Software Foundation
51 Franklin Street, Fifth Floor
Boston, MA 02110-1301
USA
The income from distribution fees goes to support the foundation's purpose: the development of new free software, and improvements to our existing programs including GNU Emacs.
If you find GNU Emacs useful, please send a donation to the Free Software Foundation to support our work. Donations to the Free Software Foundation are tax deductible in the US. If you use GNU Emacs at your workplace, please suggest that the company make a donation. If company policy is unsympathetic to the idea of donating to charity, you might instead suggest ordering a CD-ROM from the Foundation occasionally, or subscribing to periodic updates.
You are reading about GNU Emacs, the GNU incarnation of the advanced, self-documenting, customizable, extensible editor Emacs. (The `G' in `GNU' is not silent.)
We call Emacs advanced because it provides much more than simple insertion and deletion. It can control subprocesses, indent programs automatically, show two or more files at once, and edit formatted text. Emacs editing commands operate in terms of characters, words, lines, sentences, paragraphs, and pages, as well as expressions and comments in various programming languages.
Self-documenting means that at any time you can type a special character, Control-h, to find out what your options are. You can also use it to find out what any command does, or to find all the commands that pertain to a topic. See Help.
Customizable means that you can alter Emacs commands' behavior in simple ways. For example, if you use a programming language in which comments start with `<**' and end with `**>', you can tell the Emacs comment manipulation commands to use those strings (see Comments). Another sort of customization is rearrangement of the command set. For example, you can rebind the basic cursor motion commands (up, down, left and right) to any keys on the keyboard that you find comfortable. See Customization.
Extensible means that you can go beyond simple customization and write entirely new commands—programs in the Lisp language to be run by Emacs's own Lisp interpreter. Emacs is an “on-line extensible” system, which means that it is divided into many functions that call each other, any of which can be redefined in the middle of an editing session. Almost any part of Emacs can be replaced without making a separate copy of all of Emacs. Most of the editing commands of Emacs are written in Lisp; the few exceptions could have been written in Lisp but use C instead for efficiency. Writing an extension is programming, but non-programmers can use it afterwards. See Emacs Lisp Intro, if you want to learn Emacs Lisp programming.
When running on a graphical display, Emacs provides its own menus and convenient handling of mouse buttons. In addition, Emacs provides many of the benefits of a graphical display even on a text-only terminal. For instance, it can highlight parts of a file, display and edit several files at once, move text between files, and edit files while running shell commands.
On a text-only terminal, the Emacs display occupies the whole screen. On a graphical display, such as on GNU/Linux using the X Window System, Emacs creates its own windows to use. We use the term frame to mean the entire text-only screen or an entire system-level window used by Emacs. Emacs uses both kinds of frames, in the same way, to display your editing. Emacs normally starts out with just one frame, but you can create additional frames if you wish. See Frames.
When you start Emacs, the main central area of the frame, all except for the top and bottom and sides, displays the text you are editing. This area is called the window. At the top there is normally a menu bar where you can access a series of menus; then there may be a tool bar, a row of icons that perform editing commands if you click on them. Below this, the window begins, often with a scroll bar on one side. Below the window comes the last line of the frame, a special echo area or minibuffer window, where prompts appear and you enter information when Emacs asks for it. See following sections for more information about these special lines.
You can subdivide the window horizontally or vertically to make multiple text windows, each of which can independently display some file or text (see Windows). In this manual, the word “window” refers to the initial large window if not subdivided, or any one of the multiple windows you have subdivided it into.
At any time, one window is the selected window. On graphical displays, the selected window normally shows a more prominent cursor (usually solid and blinking) while other windows show a weaker cursor (such as a hollow box). Text terminals have just one cursor, so it always appears in the selected window.
Most Emacs commands implicitly apply to the text in the selected window; the text in unselected windows is mostly visible for reference. However, mouse commands generally operate on whatever window you click them in, whether selected or not. If you use multiple frames on a graphical display, then giving the input focus to a particular frame selects a window in that frame.
Each window's last line is a mode line, which describes what is going on in that window. It appears in different color and/or a “3D” box if the terminal supports them; its contents normally begin with `--:-- *scratch*' when Emacs starts. The mode line displays status information such as what buffer is being displayed above it in the window, what major and minor modes are in use, and whether the buffer contains unsaved changes.
Within Emacs, the active cursor shows the location at which editing commands will take effect. This location is called point. Many Emacs commands move point through the text, so that you can edit at different places in it. You can also place point by clicking mouse button 1 (normally the left button).
While the cursor appears to be on a character, you should think of point as between two characters; it points before the character that appears under the cursor. For example, if your text looks like `frob' with the cursor over the `b', then point is between the `o' and the `b'. If you insert the character `!' at that position, the result is `fro!b', with point between the `!' and the `b'. Thus, the cursor remains over the `b', as before.
Sometimes people speak of “the cursor” when they mean “point,” or speak of commands that move point as “cursor motion” commands.
If you are editing several files in Emacs, each in its own buffer, each buffer has its own point location. A buffer that is not currently displayed remembers its point location in case you display it again later. When Emacs displays multiple windows, each window has its own point location. If the same buffer appears in more than one window, each window has its own point position in that buffer, and (when possible) its own cursor.
A text-only terminal has just one cursor, in the selected window. The other windows do not show a cursor, even though they do have their own position of point. When Emacs updates the screen on a text-only terminal, it has to put the cursor temporarily at the place the output goes. This doesn't mean point is there, though. Once display updating finishes, Emacs puts the cursor where point is.
On graphical displays, Emacs shows a cursor in each window; the selected window's cursor is solid and blinking, and the other cursors are just hollow. Thus, the most prominent cursor always shows you the selected window, on all kinds of terminals.
See Cursor Display, for customizable variables that control display of the cursor or cursors.
The term “point” comes from the character `.', which was the command in TECO (the language in which the original Emacs was written) for accessing the value now called “point.”
The line at the bottom of the frame (below the mode line) is the echo area. It is used to display small amounts of text for various purposes.
Echoing means displaying the characters that you type. At the command line, the operating system normally echoes all your input. Emacs handles echoing differently.
Single-character commands do not echo in Emacs, and multi-character commands echo only if you pause while typing them. As soon as you pause for more than a second in the middle of a command, Emacs echoes all the characters of the command so far. This is to prompt you for the rest of the command. Once echoing has started, the rest of the command echoes immediately as you type it. This behavior is designed to give confident users fast response, while giving hesitant users maximum feedback. You can change this behavior by setting a variable (see Display Custom).
If a command cannot do its job, it may display an error message in the echo area. Error messages are accompanied by beeping or by flashing the screen. The error also discards any input you have typed ahead.
Some commands display informative messages in the echo area. These messages look much like error messages, but they are not announced with a beep and do not throw away input. Sometimes the message tells you what the command has done, when this is not obvious from looking at the text being edited. Sometimes the sole purpose of a command is to show you a message giving you specific information—for example, C-x = (hold down <CTRL> and type x, then let go of <CTRL> and type =) displays a message describing the character position of point in the text and its current column in the window. Commands that take a long time often display messages ending in `...' while they are working, and add `done' at the end when they are finished. They may also indicate progress with percentages.
Echo-area informative messages are saved in an editor buffer named `*Messages*'. (We have not explained buffers yet; see Buffers, for more information about them.) If you miss a message that appears briefly on the screen, you can switch to the `*Messages*' buffer to see it again. (Successive progress messages are often collapsed into one in that buffer.)
The size of `*Messages*' is limited to a certain number of
lines. The variable message-log-max specifies how many lines.
Once the buffer has that many lines, adding lines at the end deletes lines
from the beginning, to keep the size constant. See Variables, for
how to set variables such as message-log-max.
The echo area is also used to display the minibuffer, a window where you can input arguments to commands, such as the name of a file to be edited. When the minibuffer is in use, the echo area begins with a prompt string that usually ends with a colon; also, the cursor appears in that line because it is the selected window. You can always get out of the minibuffer by typing C-g. See Minibuffer.
Each text window's last line is a mode line, which describes what is going on in that window. The mode line starts and ends with dashes. When there is only one text window, the mode line appears right above the echo area; it is the next-to-last line in the frame. On a text-only terminal, the mode line is in inverse video if the terminal supports that; on a graphics display, the mode line has a 3D box appearance to help it stand out. The mode line of the selected window is highlighted if possible; see Optional Mode Line, for more information.
Normally, the mode line looks like this:
-cs:ch-fr buf pos line (major minor)------
This gives information about the window and the buffer it displays: the buffer's name, what major and minor modes are in use, whether the buffer's text has been changed, and how far down the buffer you are currently looking.
ch contains two stars `**' if the text in the buffer has been edited (the buffer is “modified”), or `--' if the buffer has not been edited. For a read-only buffer, it is `%*' if the buffer is modified, and `%%' otherwise.
fr gives the selected frame name (see Frames). It appears only on text-only terminals. The initial frame's name is `F1'.
buf is the name of the window's buffer. Usually this is the same as the name of a file you are editing. See Buffers.
The buffer displayed in the selected window (the window with the cursor) is the current buffer, where editing happens. When a command's effect applies to “the buffer,” we mean it does those things to the current buffer.
pos tells you whether there is additional text above the top of the window, or below the bottom. If your buffer is small and it is all visible in the window, pos is `All'. Otherwise, it is `Top' if you are looking at the beginning of the buffer, `Bot' if you are looking at the end of the buffer, or `nn%', where nn is the percentage of the buffer above the top of the window. With Size Indication mode, you can display the size of the buffer as well. See Optional Mode Line.
line is `L' followed by the current line number of point. This is present when Line Number mode is enabled (it normally is). You can display the current column number too, by turning on Column Number mode. It is not enabled by default because it is somewhat slower. See Optional Mode Line.
major is the name of the major mode in effect in the buffer. A buffer can only be in one major mode at a time. The major modes available include Fundamental mode (the least specialized), Text mode, Lisp mode, C mode, Texinfo mode, and many others. See Major Modes, for details of how the modes differ and how to select them.
Some major modes display additional information after the major mode name. For example, Rmail buffers display the current message number and the total number of messages. Compilation buffers and Shell buffers display the status of the subprocess.
minor is a list of some of the minor modes that are turned on at the moment in the window's chosen buffer. For example, `Fill' means that Auto Fill mode is on. `Abbrev' means that Word Abbrev mode is on. `Ovwrt' means that Overwrite mode is on. See Minor Modes, for more information.
`Narrow' means that the buffer being displayed has editing restricted to only a portion of its text. (This is not really a minor mode, but is like one.) See Narrowing. `Def' means that a keyboard macro is being defined. See Keyboard Macros.
In addition, if Emacs is inside a recursive editing level, square brackets (`[...]') appear around the parentheses that surround the modes. If Emacs is in one recursive editing level within another, double square brackets appear, and so on. Since recursive editing levels affect Emacs globally, not just one buffer, the square brackets appear in every window's mode line or not in any of them. See Recursive Edit.
cs states the coding system used for the file you are editing. A dash indicates the default state of affairs: no code conversion, except for end-of-line translation if the file contents call for that. `=' means no conversion whatsoever. Nontrivial code conversions are represented by various letters—for example, `1' refers to ISO Latin-1. See Coding Systems, for more information.
On a text-only terminal, cs includes two additional characters which describe the coding system for keyboard input and the coding system for terminal output. They come right before the coding system used for the file you are editing.
If you are using an input method, a string of the form `i>' is added to the beginning of cs; i identifies the input method. (Some input methods show `+' or `@' instead of `>'.) See Input Methods.
When multibyte characters are not enabled, cs does not appear at all. See Enabling Multibyte.
The colon after cs changes to another string in some cases. Emacs uses newline characters to separate lines in the buffer. Some files use different conventions for separating lines: either carriage-return linefeed (the MS-DOS convention) or just carriage-return (the Macintosh convention). If the buffer's file uses carriage-return linefeed, the colon changes to either a backslash (`\') or `(DOS)', depending on the operating system. If the file uses just carriage-return, the colon indicator changes to either a forward slash (`/') or `(Mac)'. On some systems, Emacs displays `(Unix)' instead of the colon for files that use newline as the line separator.
See Optional Mode Line, to add other handy information to the mode line, such as the size of the buffer, the current column number of point, and whether new mail for you has arrived.
The mode line is mouse-sensitive; when you move the mouse across various parts of it, Emacs displays help text to say what a click in that place will do. See Mode Line Mouse.
Each Emacs frame normally has a menu bar at the top which you can use to perform common operations. There's no need to list them here, as you can more easily see them yourself.
On a graphical display, you can use the mouse to choose a command from the menu bar. A right-arrow at the end of the menu item means it leads to a subsidiary menu; `...' at the end means that the command invoked will read arguments (further input from you) before it actually does anything.
You can also invoke the first menu bar item by pressing <F10> (to run
the command menu-bar-open). You can then navigate the menus with
the arrow keys. You select an item by pressing <RET> and cancel menu
navigation with <ESC>.
To view the full command name and documentation for a menu item, type C-h k, and then select the menu bar with the mouse in the usual way (see Key Help).
On text-only terminals with no mouse, you can use the menu bar by
typing M-` or <F10> (these run the command
tmm-menubar). This lets you select a menu item with the
keyboard. A provisional choice appears in the echo area. You can use
the up and down arrow keys to move through the menu to different
items, and then you can type <RET> to select the item.
Each menu item also has an assigned letter or digit which designates that item; it is usually the initial of some word in the item's name. This letter or digit is separated from the item name by `=>'. You can type the item's letter or digit to select the item.
Some of the commands in the menu bar have ordinary key bindings as well; one such binding is shown in parentheses after the item itself.
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, 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.
On graphical displays, the window manager is likely to block the character Meta-<TAB> before Emacs can see it. It may also block Meta-<SPC>, C-M-d and C-M-l. If you have these problems, we recommend that you customize your window manager to turn off those commands, or put them on key combinations that Emacs does not use.
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.
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
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.
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.
The usual way to invoke Emacs is with the shell command emacs. Emacs clears the screen, then displays an initial help message and copyright notice. Some operating systems discard your type-ahead when Emacs starts up; they give Emacs no way to prevent this. On those systems, wait for Emacs to clear the screen before you start typing.
From a shell window under the X Window System, run Emacs in the background with emacs&. This way, Emacs won't tie up the shell window, so you can use it to run other shell commands while Emacs is running. You can type Emacs commands as soon as you direct your keyboard input to an Emacs frame.
When Emacs starts up, it creates a buffer named `*scratch*'.
That's the buffer you start out in. The `*scratch*' buffer uses
Lisp Interaction mode; you can use it to type Lisp expressions and
evaluate them. You can also ignore that capability and just write notes
there. You can specify a different major mode for this buffer by
setting the variable initial-major-mode in your init file.
See Init File.
It is possible to specify files to be visited, Lisp files to be loaded, and functions to be called through Emacs command-line arguments. See Emacs Invocation. The feature exists mainly for compatibility with other editors, and for scripts.
Many editors are designed to edit one file. When done with that file, you exit the editor. The next time you want to edit a file, you must start the editor again. Working this way, it is convenient to use a command-line argument to say which file to edit.
However, killing Emacs after editing one each and starting it afresh for the next file is both unnecessary and harmful, since it denies you the full power of Emacs. Emacs can visit more than one file in a single editing session, and that is the right way to use it. Exiting the Emacs session loses valuable accumulated context, such as the kill ring, registers, undo history, and mark ring. These features are useful for operating on multiple files, or even continuing to edit one file. If you kill Emacs after each file, you don't take advantage of them.
The recommended way to use GNU Emacs is to start it only once, just after you log in, and do all your editing in the same Emacs session. Each time you edit a file, you visit it with the existing Emacs, which eventually has many files in it ready for editing. Usually you do not kill Emacs until you are about to log out. See Files, for more information on visiting more than one file.
To edit a file from another program while Emacs is running, you can use the emacsclient helper program to open a file in the already running Emacs. See Emacs Server.
There are two commands for exiting Emacs, and three kinds of exiting: iconifying Emacs, suspending Emacs, and killing Emacs.
Iconifying means replacing the Emacs frame with a small box or “icon” on the screen. This is the usual way to exit Emacs when you're using a graphical display—if you bother to “exit” at all. (Just switching to another application is usually sufficient.)
Suspending means stopping Emacs temporarily and returning control to its parent process (usually a shell), allowing you to resume editing later in the same Emacs job. This is the usual way to exit Emacs when running it on a text terminal.
Killing Emacs means destroying the Emacs job. You can run Emacs again later, but you will get a fresh Emacs; there is no way to resume the same editing session after it has been killed.
suspend-emacs) or iconify a frame
(iconify-or-deiconify-frame).
save-buffers-kill-emacs).
On graphical displays, C-z runs the command
iconify-or-deiconify-frame, which temporarily iconifies (or
“minimizes”) the selected Emacs frame (see Frames). You can
then use the window manager to select some other application. (You
could select another application without iconifying Emacs first, but
getting the Emacs frame out of the way can make it more convenient to
find the other application.)
On a text terminal, C-z runs the command suspend-emacs.
Suspending Emacs takes you back to the shell from which you invoked
Emacs. You can resume Emacs with the shell command %emacs
in most common shells. On systems that don't support suspending
programs, C-z starts an inferior shell that communicates
directly with the terminal, and Emacs waits until you exit the
subshell. (The way to do that is probably with C-d or
exit, but it depends on which shell you use.) On these
systems, you can only get back to the shell from which Emacs was run
(to log out, for example) when you kill Emacs.
Suspending can fail if you run Emacs under a shell that doesn't
support suspendion of its subjobs, even if the system itself does
support it. In such a case, you can set the variable
cannot-suspend to a non-nil value to force C-z to
start an inferior shell.
To exit and kill Emacs, type C-x C-c
(save-buffers-kill-emacs). A two-character key is used to make
it harder to type by accident. This command first offers to save any
modified file-visiting buffers. If you do not save them all, it asks
for confirmation with yes before killing Emacs, since any
changes not saved now will be lost forever. Also, if any subprocesses are
still running, C-x C-c asks for confirmation about them, since
killing Emacs will also kill the subprocesses.
If the value of the variable confirm-kill-emacs is
non-nil, C-x C-c assumes that its value is a predicate
function, and calls that function. If the result is non-nil, the
session is killed, otherwise Emacs continues to run. One convenient
function to use as the value of confirm-kill-emacs is the
function yes-or-no-p. The default value of
confirm-kill-emacs is nil.
You can't resume an Emacs session after killing it. Emacs can, however, record certain session information when you kill it, such as which files you visited, so the next time you start Emacs it will try to visit the same files. See Saving Emacs Sessions.
The operating system usually listens for certain special characters whose meaning is to kill or suspend the program you are running. This operating system feature is turned off while you are in Emacs. The meanings of C-z and C-x C-c as keys in Emacs were inspired by the use of C-z and C-c on several operating systems as the characters for stopping or killing a program, but that is their only relationship with the operating system. You can customize these keys to run any commands of your choice (see Keymaps).
Here we explain the basics of how to enter text, make corrections,
and save the text in a file. If this material is new to you, we
suggest you first run the Emacs learn-by-doing tutorial, by typing
Control-h t inside Emacs. (help-with-tutorial).
To clear and redisplay the screen, type C-l (recenter).
Typing printing characters inserts them into the text you are editing. It inserts them into the buffer at the cursor; more precisely, it inserts them at point, but the cursor normally shows where point is. See Point.
Insertion moves the cursor forward, and the following text moves forward with the cursor. If the text in the buffer is `FOOBAR', with the cursor before the `B', and you type XX, you get `FOOXXBAR', with the cursor still before the `B'.
To delete text you have just inserted, use the large key labeled <DEL>, <BACKSPACE> or <DELETE> which is a short distance above the <RET> or <ENTER> key. Regardless of the label on that key, Emacs thinks of it as <DEL>, and that's what we call it in this manual. <DEL> is the key you normally use outside Emacs to erase the last character that you typed.
The <DEL> key deletes the character before the cursor. As a consequence, the cursor and all the characters after it move backwards. If you type a printing character and then type <DEL>, they cancel out.
On most computers, Emacs sets up <DEL> automatically. In some cases, especially with text-only terminals, Emacs may guess wrong. If the key that ought to erase the last character doesn't do it in Emacs, see DEL Does Not Delete.
Most PC keyboards have both a <BACKSPACE> key a little ways above <RET> or <ENTER>, and a <DELETE> key elsewhere. On these keyboards, Emacs tries to set up <BACKSPACE> as <DEL>. The <DELETE> key deletes “forwards” like C-d (see below), which means it deletes the character underneath the cursor (after point).
To end a line and start typing a new one, type <RET>. (This key may be labeled <RETURN> or <ENTER>, but in Emacs we call it <RET>.) This inserts a newline character in the buffer. If point is at the end of the line, this creates a new blank line after it. If point is in the middle of a line, the effect is to split that line. Typing <DEL> when the cursor is at the beginning of a line deletes the preceding newline character, thus joining the line with the one before it.
Emacs can split lines automatically when they become too long, if you turn on a special minor mode called Auto Fill mode. See Filling, for Auto Fill mode and other methods of filling text.
If you prefer printing characters to replace (overwrite) existing text, rather than shove it to the right, you should enable Overwrite mode, a minor mode. See Minor Modes.
Only printing characters and <SPC> insert themselves in Emacs.
Other characters act as editing commands and do not insert themselves.
These include control characters, and characters with codes above 200
octal. If you need to insert one of these characters in the buffer,
you must quote it by typing the character Control-q
(quoted-insert) first. (This character's name is normally
written C-q for short.) There are two ways to use
C-q:
The use of octal sequences is disabled in ordinary non-binary Overwrite mode, to give you a convenient way to insert a digit instead of overwriting with it.
When multibyte characters are enabled, if you specify a code in the range 0200 through 0377 octal, C-q assumes that you intend to use some ISO 8859-n character set, and converts the specified code to the corresponding Emacs character code. See Enabling Multibyte. You select which of the ISO 8859 character sets to use through your choice of language environment (see Language Environments).
To use decimal or hexadecimal instead of octal, set the variable
read-quoted-char-radix to 10 or 16. If the radix is greater than
10, some letters starting with a serve as part of a character
code, just like digits.
A numeric argument tells C-q how many copies of the quoted character to insert (see Arguments).
Customization information: <DEL> in most modes runs the command
delete-backward-char; <RET> runs the command
newline, and self-inserting printing characters run the command
self-insert, which inserts whatever character you typed. Some
major modes rebind <DEL> to other commands.
To do more than insert characters, you have to know how to move point (see Point). The simplest way to do this is with arrow keys, or by clicking the left mouse button where you want to move to.
There are also control and meta characters for cursor motion. Some are equivalent to the arrow keys (it is faster to use these control keys than move your hand over to the arrow keys). Others do more sophisticated things.
move-beginning-of-line).
move-end-of-line).
forward-char). The right-arrow key
does the same thing.
backward-char). The left-arrow
key has the same effect.
forward-word).
backward-word).
next-line). This command
attempts to keep the horizontal position unchanged, so if you start in
the middle of one line, you move to the middle of the next. The
down-arrow key does the same thing.
previous-line). The up-arrow key
has the same effect. This command preserves position within the line,
like C-n.
move-to-window-line). Text does not move on the screen.
A numeric argument says which screen line to place point on, counting
downward from the top of the window (zero means the top line). A
negative argument counts lines up from the bottom (−1 means the
bottom line).
beginning-of-buffer). With
numeric argument n, move to n/10 of the way from the top.
See Arguments, for more information on numeric arguments.
end-of-buffer).
scroll-up). This