Printing Tools

 < Day Day Up > 

Text Editors

Even though you might think that you'll never have a reason to use anything other than a GUI text editor such as Alpha or BBEdit, there are a few arguments to be made for text-only mode editing in a terminal. Among them are that the text-only editors can be used even when the system can't display a GUI interface, and that an editor in a terminal can start much faster than most GUI editors. There's also the advantage that if you have occasion to work on Unix machines other than Mac OS X boxes, the command-line editors are what you will have available.

Finally, at this point, the GUI clients available currently seem to have a bit of a problem figuring out whether they should convert a file that they load into Mac-style text (for newlines) or Unix-style text. The Unix command-line editors are a bit more predictable in preferring Unix-format text. Because of this, if you're working with files in the traditional-Unix side of the system, you're probably safer sticking to the command-line editors.

When it comes to editing text on the Unix side, you'll find that many Unix programs use text files as input, create text files as output, or are configured using commands and variables set up in text files. To change the contents of these files, you'll need to use a text editor.

As a matter of fact, most Unix software doesn't know the difference between a text file and any other file. Unlike in Mac OS, from the point of view of Mac OS X's underlying Unix system, files are files are files. If the user chooses to view some of them as containing text and some as containing programs, that's the user's business. An interesting consequence of this lack of concern about a file's contents is that the operating system is just as happy to allow you to use a text editor to edit the contents of your spreadsheet program itself as it is to enable you to attempt to run your email mailbox. Of course, if you actually have execute permission turned on for your email and try to run it, it's almost certainly going to result in nothing more interesting than a bus error and an immediate exit of the command but the operating system will try to do as you command.


If you are a programmer, you might find this lack of distinction (yet another example of Unix abstraction at work) to be useful. On occasion, you might find a program that needs a minor change, such as the correction of a misspelling or a change of wording. In these instances, it is sometimes more convenient to simply load the executable file into a text editor and make the correction directly into the binary. This isn't a trick for the faint of heart, but sometimes it's the quick fix you need, and occasionally it's the only fix available for software for which you don't have access to the source.

If you spend much time discussing Unix editors with longtime Unix users, you'll find that there is a disagreement of warlike proportions between the users of the two most common editors: vi and emacs. Although these editors are actually rather complementary in their functions and are both useful tools to have in your toolbox, chances are that you will run into many users who insist that one or the other editor is completely useless. If you listen to them, instead of keeping both tools handy, you'll be depriving yourself of the better solution to at least some tasks.

Many Unix editors have immense power. emacs, for example, not only contains its own built-in programming language but can also function as a complete windowing system, a compiler/debugger interface, a news reader, and many other things. Even with a book of this size, however, there isn't space to do more than address the basics of using these editors. After you've mastered the basics, if you're interested in learning more, we encourage you to stop by your local bookstore or library and choose from among the several books available on each of the major Unix editors.

Quick, Dirty, and Omnipresent: vi

The vi editor is Unix's most universal editor. Some users pronounce it vee-eye, and some pronounce it vye, and a growing contingent claim it's pronounced six, when used on Mac OS X. There seems to be no concrete consensus which pronunciation is correct (but the people who say vye are still wrong). vi isn't an easy editor and it isn't friendly. It is, however, a quick-starting editor with a small memory footprint, which you will find on every Unix machine you encounter, regardless of flavor. vi, although annoying to learn, is frequently the most convenient editor to use for doing things such as making single-line changes to configuration files.


Apple now provides vim (vi IMproved) as a vi-replacement. vim provides some useful enhancements that are well beyond the design intent of vi. vi has historically eschewed fancy features such as syntax highlighting and multilevel undo, in favor of speed of use and ubiquity. Although it does have a sophisticated search-and-replace facility, some of vi's strongest points are that it's small, fast, and available everywhere. These features have made vi a favorite of system administrators the world over because they know, with almost certainty, that even if all they have to work with on a machine is a paper-terminal (a thing that's much like a printer with a keyboard no screen, just input on one line, output on the next, repeat…), vi will be there and work just like it does everywhere else. vim doesn't share these characteristics. It's reasonably fast on today's gigahertz processors, but it's about 20 times the size of vi in terms of disk and memory footprint, and it's by no means universally installed on all Unix systems. The improved features available in vim allow it to compete with some of the more complex emacs features, so you might find that it suits your needs as your day-to-day "power" editor, but we also recommend learning to operate comfortably within the vi subset of commands, just in case you ever need to work with the real thing.

When trying to use vi (or vim), there are a number of things you need to know to make it useful.

vi operates in one of two modes: command mode or insert mode. In command mode, you have control over things such as cursor position, deleting characters, and saving files. In command mode, every keyboard character you type will be interpreted as part of a command of some sort. In insert mode, every keyboard key you type is inserted into the file you are editing. This distinction is bound to be confusing at first, but if you use vi, you'll find that its speed makes it a preferred editor for quick changes to files. You will find the Return key included in the explanations here because some commands take effect immediately, and some require you to press Return after you enter them.

Table 13.10 shows some of the most used keys and tasks. If you're just coming to vi for the first time, don't look too long at this table yet; it will just look confusing! Flip past it to the short example of how to use vi and then turn back here and see whether, following the table, you understand what each key press did and why.

Table 13.10. Common Key Presses and the Resultant Actions in vi


Key(s)/Key Combination(s)




Moves right



Moves left



Moves to next line



Moves to previous line


Put cursor on character and press x key

Deletes character under cursor


Press d key twice

Deletes an entire line, including an empty line



Enters insert mode at end of current line



Enters insert mode before the character under the cursor



Enters insert mode after the character under the cursor


:w Return

Saves the file


:w <filename> Return

Saves the file to <filename>


:q Return



:q! Return

Quits without saving



Saves file and exit

Insert Mode

Esc key

Switches to command mode


Backspace or Delete key

Backspaces or deletes, but only for data entered in current insert mode session on the current line


Any printable keyboard

Inserts the character at the cursor character


Despite what anyone tells you, vi's not difficult to use; it just looks that way. It looks that way because any way of presenting the separate command and editing interface in a discussion, or at least any way we've ever seen or come up with, looks confusing. Try it. It's not difficult; it will make sense.

Instead of trying to walk through a screenshot-by-screenshot example of using vi, try typing the following example. Remember to compare what you're typing to the commands in Table 15.9, and watch what happens. Although the finer details are not revealed by this example, you will pick up enough to get you started doing useful work, and to get out of any sticky situations you might find yourself in while editing a file.

Try typing the following exactly as it appears here, and observe what happens. Where a new line appears in the text, press Return. Remember that <esc> is the Escape key.

 brezup:ray testing $ vi mynewfile iThis is my new file This is line one of my new file This is a test This is line four of my new file<esc>kddkA This is line three of my new file<esc>khhhhhhhhhhhhhhhhhxxxitwo<esc>:wq! 

Your machine should respond

 "mynewfile" [New file] 4 lines, 119 characters 

although you might not be able to see that because the line flashes off the screen pretty quickly. Now look at what you have:

 % cat mynewfile This is my new file This is line two of my new file This is line three of my new file This is line four of my new file 

Table 13.11 shows the syntax and common options for the vi (vim) command.

Table 13.11. The Syntax and Common Useful Options for vi (vim)


Screen-oriented text editor


Line-oriented screen editor


Read-only version of vi

vi [-eFlRrSv] [-c <cmd>] [-t <tag>] [-w <size>] [<file1> <file2> ...]

ex [-eFlRrSsv] [-c <cmd>] [-t <tag>] [-w <size>] [<file1> <file2> ...]

view [-eFlRrSv] [-c <cmd>] [-t <tag>] [-w <size>] [<file1> <file2> ...]

vi/vim is a screen-oriented text editor; ex is a line-oriented editor. vi and ex are different interfaces to the same program. view is equivalent to vi -R, the read-only option to vi.

vim has many more options than vi, but the following are the common ones you'll probably be most interested in:


Starts to edit in ex mode that is, act like the line-mode ex editor. Few people like it when they land in ex; entering q at the prompt gets you out.


Starts editing in read-only mode.

-r <recoveryfile>

Recovers the specified <recoveryfile>. If no file is specified, it lists the files that could be recovered. If no recoverable files with the specified name exist, vi starts editing as if the option has not been issued.

-c <cmd>

Executes <cmd> immediately after starting the edit session. It is especially useful for initial positioning in the file but is not limited to positioning commands.

-t <tag>

Starts editing at the specified <tag>.


Specifies that STDIN should be used as the source of the data to edit. Commands come from STDERR.

vi has two modes: command mode and input mode. Command mode is the initial and normal mode. Exiting from input mode (by pressing the Esc key) returns the user to command mode. Pressing the Esc key while in command mode aborts a partial command.

Some commands for moving around in a file:


Moves the cursor one character to the left.


Moves the cursor one character to the right.


Moves the cursor one line down.


Moves the cursor one line up.

<arrow keys>

The arrow keys often also function properly for moving around in a file. Most seasoned uses find the h/l/j/k commands faster for navigation.


Moves the cursor to the line number specified by <num>. If <num> is not specified, the cursor moves to the last line of the file.


If <key1> is a single-key command, acts as though the user had pressed the <key1> <num> times. If pressing <key1> would switch from command to editing mode, collects <key2>...<keyN> until the user presses <esc>; then acts as though the user had typed these keys <num> times in editing mode.

Some commands for inputting text (input mode):


Inserts text before the cursor.


Appends new text after the cursor.


Appends new text at the end of the line where the cursor is.


Opens a new line below the line where the cursor is and allows the user to start entering text on the new line.


Opens a new line above the line where the cursor is, and allows the user to start entering text on that new line.

Some commands for copying text:



Copies the line the cursor is on.


Appends the copied line after the line the cursor is on.

Some commands for deleting text:



Deletes the line the cursor is on.


Deletes <num> lines, starting with the line the cursor is on.


Deletes the word the cursor is on.


Deletes the character the cursor is on.

Some other useful text manipulation:


Replaces the character the cursor is on with <x>.


Joins the line the cursor is on with the line below.

Some commands for pattern searching:


Searches forward in the file for <pattern>, starting with the location of the cursor.


Searches backward in the file for <pattern>, starting with the location of the cursor.


Repeats the last / or ? pattern search.


Repeats the last / or ? pattern search in reverse.

Some commands to write the file:



Writes the file back to the filename originally specified when vi was started.

:w <filename><return>

Writes the file to the filename specified by <filename>.

Some commands to quit editing and exit vi:


Exits vi. Refuses to quit if there are any unsaved modifications, or if the file is read-only.


Exits vi, even if there are any unsaved modifications.


Exits vi, saving changes.

Miscellaneous functionality:



Switch editing to the next file specified on the command line.

Everything and the Kitchen Sink: emacs

On the other end of the spectrum from vi's odd syntax and tiny footprint is emacs. In certain circles, it is thought that emacs is an acronym for Emacs Makes a Computer Slow because emacs epitomizes the notion of an "everything" package and has the memory footprint to prove it. Including a windowing system, an email-reading client, a news-reading client, a programming language, and an online help database, to name only a few of its features, emacs can almost certainly do anything you want a plain text editor to do.


Don't believe me? emacs also includes an implementation of the aged Eliza psychoanalyst and a Zippy the Pinhead quote generator. Do you really think there's anything that's not in there? If you're creative, you can convince Zippy to have a conversation with Eliza inside emacs. Alternatively, you can play the pong video game, convert text to Morse code, manage your PIM schedule, or automatically insert keywords into your email to cause it to be flagged by the FBI's Carnivore mail-scanner as a possible terrorist threat. Browsing the categorized packages listing by entering Esc-x help<CR> p in a fresh emacs window should get you started on finding a wealth of interesting features you might never have imagined possible in a text editor.

With today's fast machines and nearly unlimited memory, the major complaints against emacs (it's a gargantuan application with a legendary hunger for computer resources hey it's not all bad people write haiku about it too!) aren't a significant impediment to its use.

From the point of view of the average user, emacs has a much more intuitive interface than vi. You're always in insert mode, just as you're used to in GUI-based word processors. Commands are handled by the use of Control+<key> combinations, instead of the use of a separate mode.

To use emacs, there are some basics that you need to know you can get more information from the online tutorial mentioned at the end of this section. In the following list, whenever you see Ctrl+ preceding a character, it means that you need to hold down the Control key and type that character. Whenever you see Esc- preceding a character, it means to press the Esc key and then the character.

  • The emacs editor doesn't have a separate mode for entering commands. You are always either typing a command or typing text no switching between modes for them. This is just like most word processors that you are probably familiar with. To enter text, just type what you want to appear. To enter a command (usually Ctrl+<key> or Esc-x <somecommand>), just type the command as shown.

  • You can position the cursor keys in emacs by using the arrow keys. If you're working across a network connection, the arrow keys might not work, but you can also position the cursor with Ctrl+<key> combinations. Ctrl+f moves the cursor forward. Ctrl+b moves it back. Ctrl+n moves to the next line. Ctrl+p moves up one line.

  • You can delete everything from the cursor to the end of the line with Ctrl+k. A second Ctrl+k deletes the now blank line.

  • Ctrl+g is the emacs "quit what you're doing" command. If you've started typing a command and change your mind, press Ctrl+g to abort.

  • If you use Ctrl+k to delete a line or lines, you can use Ctrl+y to yank it (them) back. You don't have to yank them to the same location from which you deleted them.

  • To save the file you're working on, press Ctrl+x Ctrl+s.

  • To save the file to a new name, press Ctrl+x Ctrl+w <filename> Return.

  • To exit emacs, press Ctrl+x Ctrl+c. If emacs proceeds to ask you about unsaved buffers, it's because you have unsaved work. You can either answer no and save your work, or answer yes to the "quit anyway?" questions and exit without saving.

Beyond the Ctrl+ commands available in emacs, an amazingly extensible set of commands also comes into play if you use the Escape (Esc) key. These commands are usually known as emacs meta commands, even though the machines with the meta key from which the commands draw their name have long since faded into history. These commands, even though they're initiated by pressing the Escape key, are usually abbreviated in the documentation with a leading M for meta. The complete set of these commands is the subject of more than one book, and we recommend that you investigate your library or bookstore options if you really want to understand the inner workings. If you're a puzzle solver, some of the interesting items are documented in Table 15.10. A good place to start on meta commands will be with testing out the emacs online help system. Start emacs by simply typing emacs at the prompt. After it has started, press Esc-x and then type help- and press the spacebar. You will be presented with a list of emacs commands starting with help-, including useful things such as help-for-help a good place to start.

Instead of a quick example like the one we used for vi, we suggest you take the emacs tutorial. To enter the emacs tutorial, all you need to do is start emacs and press Ctrl+h t (hold the Ctrl key, press the h key, release them both, and press the t key). If you type a ? after the Ctrl+h instead of the t, you'll see that there is actually a whole world of alternatives to the t (Ctrl+h i is another good place to look). These alternatives give you access to a range of different types of helpful information. For now, take the tutorial. If you're curious, you can probably spend almost eternity exploring the rest of the options available.

Table 13.12 shows a portion of the command documentation table for emacs as well as a listing of some of the help topics detailing a number of the available meta commands. The synopses of the help topic areas should give you an idea of some of the things that you can do, and some of the information that you can look for in the online documentation. A vastly more detailed list of capabilities can be accessed in emacs itself by typing M-x info and selecting the emacs documentation line. It should be clear even from this highly abridged listing that the complete documentation for emacs is voluminous.

Table 13.12. The Syntax and Some Useful Options for emacs



emacs [<command-line switches>] [<file1> <file2>...]

emacs is a powerful editor that can actually do more than edit files. It has an extensive information system, which can be accessed in emacs with the key sequence <Ctrl+h i> (holding down the Control key and h and then i). The information system can be navigated using the arrow keys to move around and pressing the Return key to make a selection.

emacs has an interactive help facility, <Ctrl+h>. The interactive Info information facility, which is a hierarchically organized, (usually) searchable collection of informative topic-related documents, is one type of help available. A help tutorial is available with <Ctrl+h t>. Help Apropos <Ctrl+h a> helps the user find a command given its functionality. Help Character <Ctrl+h c> describes a given character's effect.

The following are emacs options of general interest:


Edits the specified <file>.


Moves the cursor to the line number specified by <number>. (Do not include a space between + and <number>.)


Does not load an init file.

-u <user>

Loads the init file of the specified <user>.

-t <file>

Uses the specified <file> as the terminal instead of using stdin/stdout. This must be the first argument specified in the command line.


Tells emacs not to use its special X interface. When running under X11, some versions of emacs default to building an interface with a menu, which interacts (some say poorly) with the X11 cursor, allowing it to act a bit more like the traditional point-and-click editors with which you're familiar. This is sometimes convenient, but also can be incredibly annoying at times. If the -nw option is given when invoking emacs in an xterm(1) window, the emacs display is done in that window and emacs won't build its special interface. This must be the first option specified in the command line. This is useful if you're running an X server but want emacs to display in a terminal rather than the X Windows xterm or just plain don't want the special X11 interface.

The following are basic emacs key sequences. Remember that two keys pressed simultaneously have a plus sign between them, and a space indicates pressing them sequentially. Most Unix documentation, including the online man pages and info pages, will document Esc-x as M-x for the Meta key:

Up Arrow

Move cursor up one line.

Left Arrow

Move cursor to the left one character; to end of previous line if at left side of current line.

Right Arrow

Move cursor to the right one character; move to the beginning of the next line if at the right side of the current line.

Down Arrow

Move cursor down one line. Adds a new line to the file if currently on the last line of the file.


Move cursor up one line.


Move cursor to the left one character; to end of previous line if at left side of current line.


Move cursor to the right one character, move to the beginning of the next line if at the right side of the current line.


Move cursor down one line. Adds a new line to the file if currently on the last line of the file.


Move down one page in file.


Move up one page in file.


Move current line to the center of the page.


Move cursor to the beginning of the current line.


Move cursor to the end of the current line.


Move cursor to the beginning of the current sentence.


Move cursor to the end of the current sentence.

Ctrl+x Ctrl+h

Bring up list of Ctrl+x prefixed commands. (If you do this, you will see that this table is a very abbreviated list!)

Ctrl+x Ctrl+s

Save the file.

Ctrl+x Ctrl+w

Prompt for new name to save file.

Ctrl+x Ctrl+c

Exit emacs.

Ctrl+x Ctrl+f

Prompt to open file.

Ctrl+x Ctrl+b

List current file buffers.

Ctrl+x b

Prompt to switch to another buffer.


Prompt to open file in literal find-file-literally mode no Mac/Unix linefeed interpretation and so on. This is an important option for Mac users wanting to use emacs to convert Mac files to the Unix line-ending style.

Ctrl+x Ctrl+d

List directory in emacs buffer (allows opening files by browsing directory rather than by typing name).

Ctrl+x Ctrl+o

Delete blank lines in file.

Ctrl+x Ctrl+t

Transpose lines.


Set mark at the current cursor position.

Ctrl+x Ctrl+l

Downcase region. The region is the area between the cursor, and where the current mark is set.

Ctrl+x Ctrl+u

Upcase region. The region is the area between the cursor, and where the current mark is set.


Delete from mark to cursor. Deleted text goes to kill-ring buffer.


Enter incremental search mode. Any characters typed after Ctrl+s are searched for. Pressing Ctrl+s again searches for the next instance of the current search term. Use Ctrl+g, a navigation key such as the forward/backward arrows, or Ctrl+f/Ctrl+b to get out of this mode.


Enter incremental search mode, searching backward in the file.


Copy from mark to cursor into kill-ring buffer.


Delete from cursor to end of line. Place deleted text in kill-ring buffer.


Yank top data from kill-ring buffer into the text at the current cursor position.

Ctrl+x 2

Split current window vertically into two editing windows (two full-width windows, half the previous height).

Ctrl+x 3

Split current window horizontally into two editing windows (two full-height windows, half the previous width).

Ctrl+x o

Switch to next editing window in split-window mode.

Ctrl+x 1

Switch to single-window mode, keeping the current window open.

Ctrl+x 0

Remove current editing window, keeping others.

Ctrl+x (

Start recording keyboard macro.

Ctrl+x )

Stop recording keyboard macro.

Ctrl+x e

Execute recorded keyboard macro.

Ctrl+u <####>

Create a numeric argument for the next command.

Ctrl+u <####> <keyseq>

Execute <keyseq> #### times.

Ctrl+x f

Set fill column for word wrap. Requires a numeric argument set with Ctrl+u <####>.

Esc-x fill-region

Word wrap region between cursor and mark.

Ctrl+h Ctrl+h

Bring up menu of help subjects.

Ctrl+h t

Bring up emacs tutorial.

Ctrl+h i

Bring up emacs info-mode manual browser. Browsing through the emacs info through this interface is recommended.

Esc-x info

Bring up emacs info-mode manual browser.

Esc-x apropos

Prompt for command or key sequence to document.

Ctrl+h h

Bring up list of ways to say hello in 34 different languages we told you emacs had everything in it!

The following is a listing of some of the interesting parts of the information system's main menu for emacs. You're supposed to be able to find these and search the subtopics in them by using Esc-x Index-info and entering a search, but there's currently no index distributed for you to search in. Because of this, if you want more information on these topics (there are actually many more than listed here), you'll need to bring up the Info system with Ctrl+h i, navigate (using the down-arrow) to the Emacs section, and then browse the topics included there. We wish we had the space to discuss and document even a fraction of the power that emacs provides, but lacking space, a back-of-the-dustjacket listing of the features we think are most interesting will have to suffice. Think of this listing as a jumping-off place for finding your way to emacs information and a whirlwind tour of some of the options you might never have known were available in a text editor:

Basic Interest



How to get the latest emacs distribution.


The GNU General Public License gives you permission to redistribute GNU emacs on certain terms; it also explains that there is no warranty.


An introduction to emacs concepts.


The glossary.

Mac OS

Using emacs in the Mac.


What's GNU? Gnu's Not Unix!

Indexes (Nodes Containing Large Menus)

Key Index

An item for each standard emacs key sequence.

Command Index

An item for each command name.

Variable Index

An item for each documented variable.

Concept Index

An item for each concept.

Option Index

An item for every command-line option.

Important General Concepts



How to interpret what you see on the screen.

User Input

Kinds of input events (characters, buttons, function keys).


Key sequences: what you type to request one editing action.


Named functions run by key sequences to do editing.

Entering Emacs

Starting emacs from the shell.


Stopping or killing emacs.

Command Arguments

Hairy startup options.

Fundamental Editing Commands and Concepts


The most basic editing commands.


Entering arguments that are prompted for.


Invoking commands by their names.


Commands for asking emacs about its commands.

Important Text-Changing Commands and Concepts


The mark: how to delimit a region of text.


Killing text.


Recovering killed text. Moving text.

Accumulating Text

Other ways of copying text.


Operating on the text inside a rectangle on the screen.


Finding or replacing occurrences of a string.


Commands especially useful for fixing typos.

Major Structures of emacs



All about handling files.


Multiple buffers; editing several files at once.


Viewing two pieces of text at once.

Advanced Features


Major Modes

Text mode versus Lisp mode versus C mode.


Editing the whitespace at the beginnings of lines.


Commands and modes for editing English.


Commands and modes for editing programs.


Compiling, running, and debugging programs.


Features for maintaining large programs.


How to define text abbreviations to reduce the number of characters you must type.


Editing pictures made up of characters using the quarter-plane screen model.


You can "edit" a directory to manage files in it.


The calendar and diary facilities.


Executing shell commands from emacs.


Printing buffers or regions.


Printing buffers or regions as PostScript.


Sorting lines, paragraphs, or pages within emacs.


Splitting apart columns to edit them in side-by-side windows.

Editing Binary Files

Using Hexl mode to edit binary files.

Saving Emacs

Saving emacs state from one


session to the next.


Emulating some other editors with emacs.


Following links in buffers.

Dissociated Press

Dissociating text for fun.


Various games and hacks.


Modifying the behavior of emacs.

The deeper levels of the documentation include topics covering the following (and many more) useful areas:

The Organization of the Screen



The place in the text where editing commands operate.

Echo Area

Short messages appear at the bottom of the screen.

Mode Line

Interpreting the mode line.

Menu Bar

How to use the menu bar.

Basic Editing Commands


Inserting Text

Inserting text by simply typing it.

Moving Point

How to move the cursor to the place where you want to change something.


Deleting and killing text.


Undoing recent changes in the text.

Files: Basic Files

Visiting, creating, and saving files.

Continuation Lines

Lines too wide for the screen.

Position Info

What page, line, row, or column is point on?


Numeric arguments for repeating a command.

The Minibuffer


Minibuffer File

Entering filenames with the minibuffer.

Minibuffer Edit

How to edit in the minibuffer.


An abbreviation facility for minibuffer input.

Minibuffer History

Reusing recent minibuffer arguments.


Re-executing commands that used the minibuffer.



Help Summary

Brief list of all Help commands.

Key Help

Asking what a key does in Emacs.

Name Help

Asking about a command, variable, or function name.


Asking what pertains to a given topic.

The Mark and the Region


Setting Mark

Commands to set the mark.

Transient Mark

How to make emacs highlight the region when there is one.

Using Region

Summary of ways to operate on contents of the region.

Mark Ring

Previous mark positions saved so you can go back there.

Global Mark Ring

Previous mark positions in various buffers.

Deletion and Killing



Commands for deleting small amounts of text and blank areas.

Killing by Lines

How to kill entire lines of text at one time.

Other Kill Commands

Commands to kill large regions of text and syntactic units such as words and sentences.

Yanking (That Is, Pasting, for Mac Folks)

Kill Ring

Where killed text is stored. Basic yanking.

Appending Kills

Several kills in a row all yanked together.

Earlier Kills

Yanking something killed some time ago.

Controlling the Display



Moving text up and down in a window.

Horizontal Scrolling

Moving text left and right in a window.

Follow Mode

Lets two windows scroll as one.

Selective Display

Hiding lines with a lot of indentation.

Searching and Replacement


Incremental Search

Search happens as you type the string.

Nonincremental Search

Specify entire string and then search.

Word Search

Search for sequence of words.

Regexp Search

Search for match for a regular expression.


Syntax of regular expressions.


Search and replace some or all matches.

Replacement Commands


Unconditional Replace

Replacing all matches for a string.

Regexp Replace

Replacing all matches for a regular expression.

Replacement and Case

How replacements preserve case of letters.

Query Replace

How to use querying.

Commands for Fixing Typos


Kill Errors

Commands to kill a batch of recently entered text.


Exchanging two characters, words, lines, lists.

Fixing Case

Correcting case of last word entered.


Apply spelling checker to a word or a whole buffer.

Using Multiple Buffers


Select Buffer

Creating a new buffer or reselecting an old one.

List Buffers

Getting a list of buffers that exist.

Kill Buffer

Killing buffers you no longer need.

Several Buffers

How to go through the list of all buffers and operate variously on several of them.

Multiple Windows


Basic Window

Introduction to emacs windows.

Split Window

New windows are made by splitting existing windows.

Other Window

Moving to another window or doing something to it.

Pop Up Window

Finding a file or buffer in another window.

Force Same Window

Forcing certain buffers to appear in the selected window rather than in another window.

Change Window

Deleting windows and changing their sizes.

Major Modes


Choosing Modes

How major modes are specified or chosen.

Commands for Human Languages


Moving over and killing words.


Moving over and killing sentences.


Moving over paragraphs.


Moving over pages.


Filling or justifying text.


Changing the case of text.

Text Mode

The major modes for editing text files.

Outline Mode

Editing outlines.

TeX Mode

Editing input to the formatter TeX.

Nroff Mode

Editing input to the formatter nroff.

Formatted Text

Editing formatted text directly in WYSIWYG fashion.

Filling (That Is, Automatically Rewrapping) Text

Auto Fill

Auto Fill mode breaks long lines automatically.

Fill Commands

Commands to refill paragraphs and center lines.

Editing Programs


Program Modes

Major modes for editing programs.


Commands to operate on major top-level parts of a program.

Program Indent

Adjusting indentation to show the nesting.


Inserting, killing, and aligning comments.


Commands that operate on parentheses.


Getting documentation of functions you plan to call.


Displaying blocks selectively.

Symbol Completion

Completion on symbol names of your program or language.

Misc for Programs

Other emacs features useful for editing programs.

C Modes

Special commands of C, C++, Objective-C, Java, and Pike modes.


Fortran mode and its special features.

Indentation for Programs


Basic Indent

Indenting a single line.

Multi-line Indent

Commands to reindent many lines at once.

Lisp Indent

Specifying how each Lisp function should be indented.

C Indent

Extra features for indenting C and related modes.

Custom C Indent

Controlling indentation style for C and related modes.

Documentation Lookup


Info Lookup

Looking up library functions and commands in Info files.

Man Page

Looking up man pages of library functions and commands.

Lisp Doc

Looking up emacs Lisp functions, and so on.

C and Related Modes


Motion in C

Commands to move by C statements, and so on.

Electric C

Colon and other chars can automatically reindent.

Hungry Delete

A more powerful DEL command.

Other C Commands

Filling comments, viewing expansion of macros, and other neat features.

Comments in C

Options for customizing comment style.

Fortran Mode


Motion: Fortran

Moving point by statements or



Indent: Fortran

Indentation commands for Fortran.



Comments: Fortran

Inserting and aligning comments.



Autofill: Fortran Autofill

Auto fill minor mode for Fortran.

Columns: Fortran Columns.

Measuring columns for valid Fortran.

Abbrev: Fortran Abbrev.

Built-in abbreviations for Fortran keywords.

Compiling and Testing Programs



Compiling programs in languages other than Lisp (C, Pascal, and so on).

Compilation Mode

The mode for visiting compiler errors.

Compilation Shell

Customizing your shell properly for use in the compilation buffer.


Running symbolic debuggers for non-Lisp programs.

Executing Lisp

Various modes for editing Lisp programs, with different facilities for running

Lisp Eval

Executing a single Lisp expression in emacs.

Running Debuggers Under emacs


Starting GUD

How to start a debugger subprocess.

Debugger Operation

Connection between the debugger and source buffers.

Commands of GUD

Key bindings for common commands.

GUD Customization

Defining your own commands for GUD.

Dired, the Directory Editor


Dired Enter

How to invoke Dired.

Dired Navigation

How to move in the Dired buffer.

Dired Deletion

Deleting files with Dired.

Flagging Many Files

Flagging files based on their names.

Marks vs Flags

Flagging for deletion versus marking.

Operating on Files

How to copy, rename, print, compress, and so on. either one file or several files.

Shell Commands in Dired

Running a shell command on the marked files.

Transforming File Names

Using patterns to rename multiple files.

Comparison in Dired

Running diff by way of Dired.

Subdirectories in Dired

Adding subdirectories to the Dired buffer.

Subdirectory Motion

Moving across subdirectories, and up and down.

Dired and Find

Using find to choose the files for Dired.



Minor Modes

Each minor mode is one feature you can turn on independently of any others.


Many emacs commands examine emacs variables to decide what to do; by setting variables, you can control their functioning.

Keyboard Macros

A keyboard macro records a sequence of keystrokes to be replayed with a single command.

Key Bindings

The keymaps say what command each key runs. By changing them, you can redefine keys.

Keyboard Translations

If your keyboard passes an undesired code for a key, you can tell emacs to substitute another code.


The syntax table controls how words and expressions are parsed.

Init File

How to write common customizations in the .emacs file.




Examining or setting one variable's value.

Easy Customization

Convenient and easy customization of variables.


Let you specify programs for parts of emacs to run on particular occasions.


Per-buffer values of variables.

File Variables

How files can specify variable values.

Keyboard Macros


Basic Kbd Macro

Defining and running keyboard macros.

Save Kbd Macro

Giving keyboard macros names; saving them in files.

Kbd Macro Query

Making keyboard macros do different things each time.

Customizing Key Bindings



Generalities. The global keymap.

Prefix Keymaps

Keymaps for prefix keys.

Local Keymaps

Major and minor modes have their own keymaps.

Minibuffer Maps

The minibuffer uses its own local keymaps.


How to redefine one key's meaning conveniently.

Init Rebinding

Rebinding keys with your init file, .emacs.

Function Keys

Rebinding terminal function keys.

Named ASCII Chars

Distinguishing <TAB> from Ctrl+i, and so on.

Mouse Buttons

Rebinding mouse buttons in emacs.


Disabling a command means confirmation is required before it can be executed. This is done to protect beginners from surprises.

The Init File, ~/.emacs


Init Syntax

Syntax of constants in emacs Lisp.

Init Examples

How to do some things with an init file.

Terminal Init

Each terminal type can have an init file.

Find Init

How emacs finds the init file.

Dealing with emacs TRouble


DEL Does Not Delete

What to do if <DEL> doesn't delete.

Stuck Recursive

[...] in mode line around the parentheses.

Screen Garbled

Garbage on the screen.

Text Garbled

Garbage in the text.

Unasked-for Search

Spontaneous entry to incremental search.

Memory Full

How to cope when you run out of memory.

Emergency Escape

Emergency escape what to do if emacs stops responding.

Total Frustration

When you are at your wit's end.

Command-Line Options and Arguments

Action Arguments

Arguments to visit files, load libraries, and call functions.

Initial Options

Arguments that take effect while starting emacs.

Command Example

Examples of using command-line arguments.


Environment variables that emacs uses.

Environment Variables


General Variables

Environment variables that all versions of emacs use.

Misc Variables

Certain system-specific variables.

Simple and Quick: nano

If you find vi to be unfriendly and emacs to be overwhelming, you might find nano more suitable. The nano editor (the name is derived from Nano's ANOther editor, according to the man page) is a small, menu-driven windowed editing system. It is a pico clone that is distributed under the GNU license. The pico editor was developed as the editor for the pine email package. Starting with Mac OS X 10.4, nano, rather than pico, is included, and pico is just a link to nano. This change is most likely a license issue.

Being a menu-driven system, nano does not lend itself to documentation tables, so instead we will show you some output samples. It is worthwhile, though, to take a look at the man page. nano can be run with some options that you might find useful. For example, the -B flag causes nano to write a backup of your file whose name ends in ~. You can also set nano settings in a ~/.nanorc control file, which is documented in the nanorc man page.

When you run nano, you will get output that looks like this:

 GNU nano 1.2.4                  New Buffer                                   [ New File ] ^G Get Help  ^O WriteOut  ^R Read File ^Y Prev Page ^K Cut Text  ^C Cur Pos ^X Exit      ^J Justify   ^W Where Is  ^V Next Page ^U UnCut Txt ^T To Spell 

As with the pine email reader, there is a menu at the bottom to help you with using the program. After you've started typing something, the [New File] designation in the status line goes away.

When you decide to save your file, press Ctrl+O to save the file. The status line asks for the filename and the menu changes to include options pertinent to saving a file. Here is a sample of the changes you see in the nano interface:

 GNU nano 1.2.4                  New Buffer                          Modified Hi there. This is my nano test file. File Name to Write: nano-test ^G Get Help         M-D DOS Format      M-A Append          M-B Backup File ^T To Files         M-O Mac Format      M-P Prepend         ^C Cancel 

As you work with nano, you will probably find its help system to be useful. Here is the top-level help system page, which is useful for understanding other nano help pages:

 GNU nano 1.2.4                  New Buffer  nano help text  The nano editor is designed to emulate the functionality and ease-of-use  of the UW Pico text editor.  There are four main sections of the editor:  The top line shows the program version, the current filename being edited,  and whether or not the file has been modified.  Next is the main editor  window showing the file being edited.  The status line is the third line  from the bottom and shows important messages. The bottom two lines show  the most commonly used shortcuts in the editor.  The notation for shortcuts is as follows: Control-key sequences are  notated with a caret (^) symbol and are entered with the Control (Ctrl)  key.  Escape-key sequences are notated with the Meta (M) symbol and can be  entered using either the Esc, Alt or Meta key depending on your keyboard  setup.  The following keystrokes are available in the main editor window.  Alternative keys are shown in parentheses: ^G      (F1)            Invoke the help menu ^X      (F2)            Close currently loaded file/Exit from nano ^Y Prev Page                            ^X Exit ^V Next Page 

     < Day Day Up > 

    Mac OS X Tiger Unleashed
    Mac OS X Tiger Unleashed
    ISBN: 0672327465
    EAN: 2147483647
    Year: 2005
    Pages: 251 © 2008-2017.
    If you may any questions please contact us: