-->
Previous Table of Contents Next


Chapter 28
Using the emacs Editor

by Jack Tackett

In this chapter
Starting emacs
Using emacs
Writing Files and Saving the Buffer
Basic Command Summary
Customizing emacs

The name emacs stands for Editor MACroS, which began life as a replacement for an early text editor named teco. emacs is one of the most used, most widely ported editors available in the UNIX/Linux world today. In fact, versions of emacs are available on almost every computing platform known to the industry, from Linux to Microsoft Windows.

A full version of emacs is very large, taking up several megabytes of disk space. It’s a full-featured editor, very powerful, and has been extended for functions beyond text editing. In some installations, you can use it to edit files, keep a calendar, work with e-mail, manage files, read UseNet or network news, create outlines, use it as a calculator, and even browse the World Wide Web. In some ways, emacs is a working environment that contains a text editor. A popular version of emacs is distributed via the GNU license. This is the version of emacs Linux installed during installation.

Starting emacs

GNU patriarch Richard Stallman created the emacs editor. The source code for emacs is essentially available for free under the GNU licenses. Stallman is the founder and proponent of the Free Software Foundation and the GNU (GNU’s Not UNIX) project. The fact that emacs is freely available matches Stallman’s philosophy that all software should be free and that computer systems should be open for use by anyone. Users are also encouraged to make modifications but must then share those changes with others.


See “The GNU License,” p. 800

The emacs editor doesn’t have the two basic modes that vi does, which means that anything you type is put into the file buffer. To give the editor commands to save files, search for text, delete text, and so on, you must use other keys. In emacs, you use the <Ctrl> key in combination with various characters (usually <Ctrl-x> and <Ctrl-c>) and the <Esc> key to accomplish the various commands. A variety of common commands are described later in this chapter.


See “Looking at vi ’s Two Modes,” p. 182

These emacs commands are actually shortcuts for the full text commands. For example, <Ctrl-x><Ctrl-s>, which saves the current buffer to a file, is actually a shortcut freeing the user from pressing <Esc> and then typing the actual emacs command: -x save-buffer. As you can see, using the <Ctrl-x><Ctrl-s> key sequence is a lot more simple and much easier to remember than the full emacs command. A brief list of the basic commands is presented at the end of this chapter.

emacs also allows you to edit multiple buffers, or files, in the same session. That is, you can edit more than one file at a time with emacs. This chapter also covers some of the buffer-manipulation commands. emacs also uses buffers to hold deleted text and also to prompt for commands.

To start emacs, type emacs and press <Return>. A blank screen with a status line at the bottom appears.

This chapter doesn’t discuss all the keystrokes and commands used in emacs, but you can get help by pressing <Ctrl-h><h>. After that, you can use <Ctrl-x><Ctrl-c> to exit completely, or <Ctrl-x><1> to return to your editing session. Thus, unlike vi, emacs has online help facilities and even a tutorial.

After you ask for online help, emacs presents another buffer and is ready to provide help. If you press <t>, emacs starts an excellent tutorial. If you press <k>, emacs provides help on the next command/key you enter. Thus, if you pressed <Ctrl-h><k><Ctrl-w>, emacs presents information on deleting a marked region.

To return to your editing session, press <Ctrl-x><1> to return emacs to editing only one buffer.

The complete GNU emacs system is large but can be customized to match your local environment. Some smaller versions of emacs that are readily available are Freemacs by Russell Nelson and MicroEmacs, originally by Dave Conroy. Remember too that the Linux distribution provides for a few other emacs -like editors—namely JEDand JOVE, which are much smaller in size than the full emacs installation.


NOTE:  This chapter doesn’t cover all the features of emacs—that would take more space than is available. In fact, there are entire books written just on emacs. Instead, you learn the commands to do most necessary editing tasks. If you want to know about the more advanced features of emacs and advanced text-editing operations, consult the reference manual supplied with your system. You don’t have to become an emacs expert to use it. emacs also has a very detailed tutorial as part of the system. More information on running the tutorial is presented later in this chapter, but you can start the tutorial by pressing <Ctrl-h><t>.


Previous Table of Contents Next