Book HomeBook TitleSearch this book

Chapter 7. The Emacs Editor

Contents:

Introduction
Summary of Commands by Group
Summary of Commands by Key
Summary of Commands by Name

This chapter presents the following topics:

For more information about emacs, see Learning GNU Emacs, listed in the Bibliography.

7.1. Introduction

Although emacs is not part of SVR4 or Solaris,[8] this text editor is found on many Unix systems because it is a popular alternative to vi. This book documents GNU emacs (Version 20.3), which is available from the Free Software Foundation (http://www.gnu.org).

[8]The Sun Workshop programming environment, available separately from Sun, does come with Xemacs, a derivative of GNU emacs.

To start an emacs editing session, type:

emacs [file]

On some systems, GNU emacs is invoked by typing gmacs instead of emacs.

7.1.1. Notes on the Tables

emacs commands use the Control key and the Meta key (Meta is usually the Escape key). In this chapter, the notation C- indicates that the Control key is pressed at the same time as the character that follows. Similarly, M- indicates the use of the Meta key. When Meta is simulated by the Escape key, it's not necessary to keep the Meta key pressed down while typing the next key. But if your keyboard actually has a Meta key, then it is just like Control or Shift, and you should press it simultaneously with the other key(s).

In the command tables that follow, the first column lists the keystroke and the last column describes it. When there is a middle column, it lists the command name. This name is accessed by typing M-x followed by the command name. If you're unsure of the name, you can type a space or a carriage return, and emacs lists possible completions of what you've typed so far.

Because emacs is such a comprehensive editor, containing literally thousands of commands, some commands must be omitted for the sake of preserving a “quick” reference. You can browse the command set by typing C-h (for help) or M-x (for command names).

7.1.2. Absolutely Essential Commands

If you're just getting started with emacs, here's a short list of the most important commands:

KeystrokesDescription
C-h

Enter the online help system.

C-x C-s

Save the file.

C-x C-c

Exit emacs.

C-x u

Undo last edit (can be repeated).

C-g

Get out of current command operation.

C-p

C-n

C-f

C-b

Up/down/forward/back by line or character.

C-v

M-v

Forward/backward by one screen.

C-s

C-r

Search forward/backward for characters.

C-d

Del

Delete next/previous character.

7.1.3. Typical Problems

A very common problem is that the Del or Backspace key on the terminal does not delete the character before the cursor, as it should. Instead, it invokes a help prompt. This problem is caused by an incompatible terminal. A fairly robust fix is to create a file named .emacs in your home directory (or edit one that's already there) and add the following lines:

(keyboard-translate ?\C-h ?\C-?)
(keyboard-translate ?\C-\\ ?\C-h)

Now the Del or Backspace key should work, and you can invoke help by pressing C-\ (an arbitrarily chosen key sequence).

Another problem that could happen when you are logged in from a remote terminal is that C-s may cause the terminal to hang. This is caused by an old-fashioned handshake protocol between the terminal and the system. You can restart the terminal by pressing C-q, but that doesn't help you enter commands that contain the sequence C-s. The only solution (aside from using a more modern dial-in protocol) is to create new key bindings that replace C-s.



Library Navigation Links

Copyright © 2003 O'Reilly & Associates. All rights reserved.