Ex/Edit Command Summary (Version 2.0)

Ex and edit are text editors, used for creating and modifying files of text on the UNIX computer system. Edit is a variant of ex with features designed to make it less complicated to learn and use. In terms of command syntax and effect the editors are essentially identical, and this command summary applies to both.

The summary is meant as a quick reference for users already acquainted with edit or ex. Fuller explanations of the editors are available in the documents Edit: A Tutorial (a self-teaching introduction) and the Ex Reference Manual (the comprehensive reference source for both edit and ex). Both of these writeups are available in the Computing Services Library.

In the examples included with the summary, commands and text entered by the user are printed in boldface to distinguish them from responses printed by the computer.

The Editor Buffer

In order to perform its tasks the editor sets aside a temporary work space, called a buffer, separate from the user’s permanent file. Before starting to work on an existing file the editor makes a copy of it in the buffer, leaving the original untouched. All editing changes are made to the buffer copy, which must then be written back to the permanent file in order to update the old version. The buffer disappears at the end of the editing session.

Editing: Command and Text Input Modes

During an editing session there are two usual modes of operation: command mode and text input mode. (This disregards, for the moment, open and visual modes, discussed below.) In command mode, the editor issues a colon prompt (:) to show that it is ready to accept and execute a command. In text input mode, on the other hand, there is no prompt and the editor merely accepts text to be added to the buffer. Text input mode is initiated by the commands append, insert, and change, and is terminated by typing a period as the first and only character on a line.

Line Numbers and Command Syntax

The editor keeps track of lines of text in the buffer by numbering them consecutively starting with 1 and renumbering as lines are added or deleted. At any given time the editor is positioned at one of these lines; this position is called the current line. Generally, commands that change the contents of the buffer print the new current line at the end of their execution.

Most commands can be preceded by one or two line-number addresses which indicate the lines to be affected. If one number is given the command operates on that line only; if two, on an inclusive range of lines. Commands that can take line-number prefixes also assume default prefixes if none are given. The default assumed by each command is designed to make it convenient to use in many instances without any line-number prefix. For the most part, a command used without a prefix operates on the current line, though exceptions to this rule should be noted. The print command by itself, for instance, causes one line, the current line, to be printed at the terminal.

The summary shows the number of line addresses that can be prefixed to each command as well as the defaults assumed if they are omitted. For example, (.,.) means that up to 2 line-numbers may be given, and that if none is given the command operates on the current line. (In the address prefix notation, ‘‘.’’ stands for the current line and ‘‘$’’ stands for the last line of the buffer.) If no such notation appears, no line-number prefix may be used.

Some commands take trailing information; only the more important instances of this are mentioned in the summary.

Open and Visual Modes

Besides command and text input modes, ex and edit provide on some CRT terminals other modes of editing, open and visual. In these modes the cursor can be moved to individual words or characters in a line. The commands then given are very different from the standard editor commands; most do not appear on the screen when typed. An Introduction to Display Editing with Vi provides a full discussion.

Special Characters

Some characters take on special meanings when used in context searches and in patterns given to the substitute command. For edit, these are ‘‘^’’ and ‘‘$’’, meaning the beginning and end of a line, respectively. Ex has the following additional special characters:

. & * [ ] ~

To use one of the special characters as its simple graphic representation rather than with its special meaning, precede it by a backslash (\). The backslash always has a special meaning.