GNU Emacs Manual


Next: , Previous: (dir), Up: (dir)

The Emacs Editor

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.0.50.

For information on extending Emacs, see Emacs Lisp.

Indexes (nodes containing large menus)

Important General Concepts

Fundamental Editing Commands

Important Text-Changing Commands

Major Structures of Emacs

Advanced Features

Recovery from Problems

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

Help

The Mark and the Region

Killing and Moving Text

Yanking

Registers

Controlling the Display

Searching and Replacement

Replacement Commands

Commands for Fixing Typos

Keyboard Macros

File Handling

Saving Files

Version Control

Using Multiple Buffers

Multiple Windows

Frames and X Windows

International Character Set Support

Major Modes

Indentation

Commands for Human Languages

Filling Text

Editing Programs

Top-Level Definitions, or Defuns

Indentation for Programs

Commands for Editing with Parentheses

Manipulating Comments

Documentation Lookup

C and Related Modes

Fortran Mode

Compiling and Testing Programs

Running Debuggers Under Emacs

Maintaining Programs

Tags Tables

Merging Files with Emerge

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

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

MS-DOS and Windows 95/98/NT


Next: , Previous: Top, Up: Top

Distribution

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.


Next: , Previous: Distrib, Up: Top

Introduction

You are reading about GNU Emacs, the GNU incarnation of the advanced, self-documenting, customizable, extensible real-time display editor Emacs. (The `G' in `GNU' is not silent.)

We say that Emacs is a display editor because normally the text being edited is visible on the screen and is updated automatically as you type your commands. See Display.

We call it a real-time editor because the display is updated very frequently, usually after each character or pair of characters you type. This minimizes the amount of information you must keep in your head as you edit. See Real-time.

We call Emacs advanced because it provides facilities that go beyond simple insertion and deletion: controlling subprocesses; automatic indentation of programs; viewing two or more files at once; editing formatted text; and dealing in terms of characters, words, lines, sentences, paragraphs, and pages, as well as expressions and comments in several different 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 change the definitions of Emacs commands in little 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, if you prefer the four basic cursor motion commands (up, down, left and right) on keys in a diamond pattern on the keyboard, you can rebind the keys that way. 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 are written in C for efficiency. Although only a programmer can write an extension, anybody can use it afterward. See Emacs Lisp Intro, if you want to learn Emacs Lisp programming.

When run under the X Window System, Emacs provides its own menus and convenient bindings to mouse buttons. But Emacs can provide many of the benefits of a window system on a text-only terminal. For instance, you can look at or edit several files at once, move text between files, and edit files while running shell commands.


Next: , Previous: Acknowledgments, Up: Top

1 The Organization of the Screen

On a text-only terminal, the Emacs display occupies the whole screen. On the X Window System, Emacs creates its own X windows to use. We use the term frame to mean an entire text-only screen or an entire X 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 entire frame except for the top and bottom is devoted to 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. The last line is a special echo area or minibuffer window, where prompts appear and where you enter information when Emacs asks for it. See below for more information about these special lines.

You can subdivide the large text window horizontally or vertically into multiple text windows, each of which can be used for a different file (see Windows). In this manual, the word “window” always refers to the subdivisions of a frame within Emacs.

At any time, one window is the selected window. On graphical terminals, the selected window normally shows a more prominent cursor (solid and blinking) while other windows show a weaker cursor (such as a hollow box). On text terminals, which have just one cursor, that cursor appears in the selected window.

Most Emacs commands implicitly apply to the text in the selected window (though mouse commands generally operate on whatever window you click them in, whether selected or not). The other windows display text for reference only, unless/until you select them. If you use multiple frames under the X Window System, 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 that; 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.


Next: , Up: Screen

1.1 Point

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.

While the cursor appears to point at 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 position for point in that buffer, and (when possible) its own cursor.

A text-only terminal has just one cursor, so Emacs puts it in the selected window. The other windows do not show a cursor, even though they do have a location 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 terminals, 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.”


Next: , Previous: Point, Up: Screen

1.2 The Echo Area

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 be executed, 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.

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, each line added at the end deletes one line from the beginning. See Variables, for how to set variables such as message-log-max.

The echo area is also used to display the minibuffer, a window that is used for reading 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.


Next: , Previous: Echo Area, Up: Screen

1.3 The Mode Line

Each text window's last line is a mode line, which describes what is going on in that window. 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. The mode line starts and ends with dashes. On a text-mode display, 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 has a slightly different appearance than those of other windows; see Optional Mode Line, for more about this.

Normally, the mode line looks like this:

     -cs:ch  buf      pos line   (major minor)------

This gives information about the buffer being displayed in the window: 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.

buf is the name of the window's buffer. In most cases this is the same as the name of a file you are editing. See Buffers.

The buffer displayed in the selected window (the window that the cursor is in) is also Emacs's current buffer, the one that editing takes place in. When we speak of what some command does to “the buffer,” we are talking about 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 (which it normally is). You can optionally display the current column number too, by turning on Column Number mode (which 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. At any time, each buffer is in one and only one of the possible major modes. 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 one.

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 currently 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.

Non-windowing terminals can only show a single Emacs frame at a time (see Frames). On such terminals, the mode line displays the name of the selected frame, after ch. The initial frame's name is ‘F1’.

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. 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 you are using a character-only terminal (not a window system), cs uses three characters to describe, respectively, the coding system for keyboard input, the coding system for terminal output, and the coding system used for the file you are editing.

When multibyte characters are not enabled, cs does not appear at all. See Enabling Multibyte.

The colon after cs can change to another string in certain circumstances. 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 even for files that use newline to separate lines.

You can customize the mode line display for each of the end-of-line formats by setting each of the variables eol-mnemonic-unix, eol-mnemonic-dos, eol-mnemonic-mac, and eol-mnemonic-undecided to any string you find appropriate. See Variables, for an explanation of how to set variables.

See Optional Mode Line, for features that add other handy information to the mode line, such as the size of the buffer, the current column number of point, the current time, 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.


Previous: Mode Line, Up: Screen

1.4 The Menu Bar

Each Emacs frame normally has a menu bar at the top which you can use to perform certain common operations. There's no need to list them here, as you can more easily see for yourself.

When you are using a window system, you can use the mouse to choose a command from the menu bar. An arrow pointing right, after the menu item, indicates that the item leads to a subsidiary menu; ‘...’ at the end means that the command will read arguments (further input from you) before it actually does anything.

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 command enters a mode in which you can select a menu item from 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 choices. When you have found the choice you want, type <RET> to select it.

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; if so, the menu lists one equivalent key binding in parentheses after the item itself.


Next: , Previous: Screen, Up: Top

2 Kinds of User Input

GNU 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 referred to below as <SPC>, even though strictly speaking it is a graphic character whose graphic happens to be blank. Some keyboards have a key labeled “linefeed” which is an alias for C-j.

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.

But the Emacs character set has room for control variants of all printing characters, and for distinguishing between C-a and C-A. The X Window System makes it possible to enter all these characters. For example, C-- (that's Control-Minus) and C-5 are meaningful Emacs commands under X.

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 (not the same character as M-a, but those two characters normally have the same meaning in Emacs), M-<RET>, and M-C-a. For reasons of tradition, we usually write C-M-a rather than M-C-a; logically speaking, the order in which the modifier keys <CTRL> and <META> are mentioned does not matter.

Some terminals have a <META> key, and allow you to type Meta characters by holding this key down. Thus, Meta-a is typed by holding down <META> and pressing a. The <META> key works much like the <SHIFT> key. Such a key is not always labeled <META>, however, as this function is often a special option for a key with some other primary purpose. Sometimes it is labeled <ALT> or <EDIT>; 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.

The X Window System provides 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 X 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: for example function keys and arrow keys. Mouse buttons are also outside the gamut of characters. 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 more information. 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 recognize these special sequences and convert them to function key events before any other part of Emacs gets to see them.


Next: , Previous: User Input, Up: Top

3 Keys

A key sequence (key, for short) is a sequence of input events that are meaningful as a unit—as “a single command.” Some Emacs command sequences are just one character or one event; for example, just C-f is enough to move 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.

By contrast, you can't add more 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-o and M-g. (<F1> and <F2> are aliases for C-h and C-x 6.) But this list is not cast in concrete; it is just a matter of Emacs's standard key bindings. If you customize Emacs, you can make new prefix keys, or eliminate these. See Key Bindings.

If you do 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 (or C-x 4 anything) is no longer a key.

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 for which C-h does not work—for historical reasons, they have other meanings for C-h which are not easy to change. But <F1> should work for all prefix keys.


Next: , Previous: Keys, Up: Top

4 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 what makes the command do what it does. In Emacs Lisp, a command is actually a special kind of Lisp function; one which specifies how to read arguments for it and call it interactively. For more information on commands and functions, see What Is a Function. (The definition we use in this manual is simplified slightly.)

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

When we say that “C-n moves down vertically one line” we are glossing over a distinction that is irrelevant in ordinary use but is vital in understanding how to customize Emacs. It is the command next-line that is programmed to move down vertically. C-n has this effect because it is bound to that command. If you rebind C-n to the command forward-word then C-n will move forward by words instead. Rebinding keys is a common 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 a key is bound to some command. To give the information needed for customization, 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 next-line is a command that moves vertically down, and C-n is a key that is normally bound to it.

While we are on the subject of information for customization only, it's a good time to 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 remember a value. Most of the variables documented in this manual exist just to facilitate customization: some command or other part of Emacs examines the variable and behaves differently according to the value that you set. Until you are interested in customizing, you can ignore the information about variables. When you are ready to be interested, read the basic information on variables, and then the information on individual variables will make sense. See Variables.


Next: , Previous: Commands, Up: Top

5 Character Set for Text

Text in Emacs buffers is a sequence of 8-bit bytes. Each byte can hold a single ASCII character. Both ASCII control characters (octal codes 000 through 037, and 0177) and ASCII printing characters (codes 040 through 0176) are allowed; however, non-ASCII control characters cannot appear in a buffer. The other modifier flags used in keyboard input, such as Meta, are not allowed in buffers either.

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.

Non-ASCII printing characters can also appear in buffers. When multibyte characters are enabled, you can use any of the non-ASCII printing characters that Emacs supports. 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.

If you disable multibyte characters, then you can use only one alphabet of non-ASCII characters, but they all fit in one byte. They use codes 0200 through 0377. See Single-Byte Character Support.


Next: , Previous: Text Characters, Up: Top

6 Entering and Exiting Emacs

The usual way to invoke Emacs is with the shell command emacs. Emacs clears the screen and then displays an initial help message and copyright notice. Some operating systems discard all type-ahead when Emacs starts up; they give Emacs no way to prevent this. Therefore, it is advisable to wait until Emacs clears the screen before typing your first editing command.

If you run Emacs from a shell window under the X Window System, run it in the background with emacs&. This way, Emacs does not tie up the shell window, so you can use that to run other shell commands while Emacs operates its own X windows. You can begin typing Emacs commands as soon as you direct your keyboard input to the 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, or you can ignore that capability and simply doodle. (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, by giving Emacs arguments in the shell command line. See Emacs Invocation. But we don't recommend doing this. The feature exists mainly for compatibility with other editors.

Many other editors are designed to be started afresh each time you want to edit. You edit one file and then exit the editor. The next time you want to edit either another file or the same one, you must run the editor again. With these editors, it makes sense to use a command-line argument to say which file to edit.

But starting a new Emacs each time you want to edit a different file does not make sense. This would fail to take advantage of Emacs's ability to visit more than one file in a single editing session, and it would lose the other accumulated context, such as the kill ring, registers, undo history, and mark ring, that are useful for operating on multiple files.

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 want to edit a different file, you visit it with the existing Emacs, which eventually comes to have many files in it ready for editing. Usually you do not kill the Emacs until you are about to log out. See Files, for more information on visiting more than one file.

If you want to edit a file from another program and already have Emacs running, you can use the emacsclient program to open a file in the already running Emacs. See Emacs Server, for more information on editing files with Emacs from other programs.


Next: , Previous: Entering Emacs, Up: Top

7 Exiting Emacs

There are two commands for exiting Emacs because there are three kinds of exiting: suspending Emacs, Iconifying Emacs, and killing Emacs.

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, with the same buffers, same kill ring, same undo history, and so on. This is the usual way to exit Emacs when running on a text terminal.

Iconifying means replacing the Emacs frame with a small box somewhere on the screen. This is the usual way to exit Emacs when you're using a graphics 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.

C-z
Suspend Emacs (suspend-emacs) or iconify a frame (iconify-or-deiconify-frame).
C-x C-c
Kill Emacs (save-buffers-kill-emacs).

To suspend or iconify Emacs, type C-z (suspend-emacs). On text terminals, this suspends Emacs. On graphics terminals, it iconifies the Emacs frame.

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. 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.) The only way on these systems to get back to the shell from which Emacs was run (to log out, for example) is to kill Emacs.

Suspending can fail if you run Emacs under a shell that doesn't support suspending programs, 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. (One might also describe Emacs's parent shell as “inferior” for failing to support job control properly, but that is a matter of taste.)

On graphics terminals, C-z has a different meaning: it runs the command iconify-or-deiconify-frame, which temporarily iconifies (or “minimizes”) the selected Emacs frame (see Frames). Then you can use the window manager to get back to a shell window.

To exit and kill Emacs, type C-x C-c (save-buffers-kill-emacs). A two-character key is used for this 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 reconfirmation with yes before killing Emacs, since any changes not saved 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.

There is no way to resume an Emacs session once you have killed it. You can, however, arrange for Emacs to record certain session information when you kill it, such as which files are visited, so that the next time you start Emacs it will try to visit the same files and so on. 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).


Next: , Previous: Exiting, Up: Top

8 Basic Editing Commands

We now give the basics of how to enter text, make corrections, and save the text in a file. If this material is new to you, you might learn it more easily by running the Emacs learn-by-doing tutorial. To use the tutorial, run Emacs and type Control-h t (help-with-tutorial).

To clear the screen and redisplay, type C-l (recenter).


Next: , Up: Basic

8.1 Inserting Text

To insert printing characters into the text you are editing, just type them. This inserts the characters you type into the buffer at the cursor (that is, at point; see Point). The cursor moves forward, and any text after the cursor moves forward too. If the text in the buffer is ‘FOOBAR’, with the cursor before the ‘B’, then if 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. This is the key you normally use, outside Emacs, for erasing the last character that you typed. Regardless of the label on that key, Emacs thinks of it as <DEL>, and that's what we call it in this manual.

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 recognizes automatically which key ought to be <DEL>, and sets it up that way. But in some cases, especially with text-only terminals, you will need to tell Emacs which key to use for that purpose. If the large key not far above the <RET> or <ENTER> key doesn't delete backwards, you need to do this. See DEL Does Not Delete, for an explanation of how.

Most PC keyboards have both a <BACKSPACE> key a short ways above <RET> or <ENTER>, and a <DELETE> key elsewhere. On these keyboards, Emacs supports when possible the usual convention that the <BACKSPACE> key deletes backwards (it is <DEL>), while the <DELETE> key deletes “forwards,” deleting the character after point, the one underneath the cursor, like C-d (see below).

To end a line and start typing a new one, type <RET>. This inserts a newline character in the buffer. If point is in the middle of a line, the effect is to split the line. Typing <DEL> when the cursor is at the beginning of a line deletes the preceding newline, thus joining the line with the preceding line.

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 how to use Auto Fill mode.

If you prefer to have text characters replace (overwrite) existing text rather than shove it to the right, you can enable Overwrite mode, a minor mode. See Minor Modes.

Direct insertion works for printing characters and <SPC>, but other characters act as editing commands and do not insert themselves. If you need to insert a control character or a character whose code is above 200 octal, 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:

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 to C-q specifies how many copies of the quoted character should be inserted (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 was typed to invoke it. Some major modes rebind <DEL> to other commands.


Next: , Previous: Inserting Text, Up: Basic

8.2 Changing the Location of Point

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 (these date back to the days before terminals had arrow keys, and are usable on terminals which don't have them). Others do more sophisticated things.

C-a
Move to the beginning of the line (move-beginning-of-line).
C-e
Move to the end of the line (move-end-of-line).
C-f
Move forward one character (forward-char). The right-arrow key does the same thing.
C-b
Move backward one character (backward-char). The left-arrow key has the same effect.
M-f
Move forward one word (forward-word).
M-b
Move backward one word (backward-word).
C-n
Move down one line, vertically (next-line). This command attempts to keep the horizontal position unchanged, so if you start in the middle of one line, you end in the middle of the next. The down-arrow key does the same thing.
C-p
Move up one line, vertically (previous-line). The up-arrow key has the same effect.
M-r
Move point to left margin, vertically centered in the window (move-to-window-line). Text does not move on the screen.

A numeric argument says which screen line to place point on. It counts screen lines down from the top of the window (zero for the top line). A negative argument counts lines from the bottom (−1 for the bottom line).

M-<
Move to the top of the buffer (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.
M->
Move to the end of the buffer (end-of-buffer).
C-v
<PAGEDOWN>
<PRIOR>
Scroll the display one screen forward, and move point if necessary to put it on the screen (scroll-up). This doesn't always move point, but it is commonly used to do so. If your keyboard has a <PAGEDOWN> or <PRIOR> key, it does the same thing.

Scrolling commands are further described in Scrolling.

M-v
<PAGEUP>
<NEXT>
Scroll one screen backward, and move point if necessary to put it on the screen (scroll-down). This doesn't always move point, but it is commonly used to do so. If your keyboard has a <PAGEUP> or <NEXT> key, it does the same thing.
M-x goto-char
Read a number n and move point to buffer position n. Position 1 is the beginning of the buffer.
M-g M-g
M-g g
M-x goto-line
Read a number n and move point to the beginning of line number n. Line 1 is the beginning of the buffer. If point is on or just after a number, then that is the default for n, if you just press <RET> with an empty minibuffer.
C-x C-n
Use the current column of point as the semipermanent goal column for C-n and C-p (set-goal-column). Henceforth, those commands always move to this column in each line moved into, or as close as possible given the contents of the line. This goal column remains in effect until canceled.
C-u C-x C-n
Cancel the goal column. Henceforth, C-n and C-p once again try to stick to a fixed horizontal position, as usual.

If you set the variable track-eol to a non-nil value, then C-n and C-p, when starting at the end of the line, move to the end of another line. Normally, track-eol is nil. See Variables, for how to set variables such as track-eol.

C-n normally stops at the end of the buffer when you use it on the last line of the buffer. But if you set the variable next-line-add-newlines to a non-nil value, C-n on the last line of a buffer creates an additional line at the end and moves down onto it.


Next: , Previous: Moving Point, Up: Basic

8.3 Erasing Text

<DEL>
Delete the character before point (delete-backward-char).
C-d
Delete the character after point (delete-char).
<DELETE>
<BACKSPACE>
One of these keys, whichever is the large key above the <RET> or <ENTER> key, deletes the character before point, like <DEL>. If that is <BACKSPACE>, and your keyboard also has <DELETE>, then <DELETE> deletes forwards, like C-d.
C-k
Kill to the end of the line (kill-line).
M-d
Kill forward to the end of the next word (kill-word).
M-<DEL>
Kill back to the beginning of the previous word (backward-kill-word).

You already know about the <DEL> key which deletes the character before point (that is, before the cursor). Another key, Control-d (C-d for short), deletes the character after point (that is, the character that the cursor is on). This shifts the rest of the text on the line to the left. If you type C-d at the end of a line, it joins together that line and the next line.

To erase a larger amount of text, use the C-k key, which kills a line at a time. If you type C-k at the beginning or middle of a line, it kills all the text up to the end of the line. If you type C-k at the end of a line, it joins that line and the next line.

See Killing, for more flexibl