The ex utility is the root of a family of editors: ex and vi. ex is a superset of ed(1), with the most notable extension being a display editing facility. Display based editing is the focus of vi.
If you have a CRT terminal, you may wish to use a display based editor; in this case see vi(1), which is a command which focuses on the display-editing portion of ex.
If you have used ed you will find that, in addition to having all of the ed commands available, ex has a number of additional features useful
on CRT terminals. Intelligent terminals and high speed terminals are very pleasant to use with vi. Generally, the ex editor uses far more of the
capabilities of terminals than ed does, and uses the terminal capability data base (see terminfo(4)) and the type of the terminal you are using from the environment variable TERM to determine how to drive your terminal efficiently. The editor
makes use of features such as insert and delete character and line in its visual command (which can be abbreviated vi) and which is the central mode of editing when
using the vi command.
The ex utility contains a number of features for easily viewing the text of the file. The z command gives easy access to windows of text. Typing ^D (CTRL-D) causes the editor to scroll a half-window of text and is more useful for quickly stepping through a file than just typing return. Of course, the screen-oriented visual
mode gives constant access to editing context.
The ex utility gives you help when you make mistakes. The undo (u) command allows you to reverse any single change which goes astray. ex gives you a lot of feedback, normally printing changed lines, and indicates when more than a few lines are affected by a command so that it is easy to detect when a command has affected more
lines than it should have.
The editor also normally prevents overwriting existing files, unless you edited them, so that you do not accidentally overwrite a file other than the one you are editing. If the system (or editor)
crashes, or you accidentally hang up the telephone, you can use the editor recover command (or -r file option) to retrieve your work. This will
get you back to within a few lines of where you left off.
The ex utility has several features for dealing with more than one file at a time. You can give it a list of files on the command line and use the next (n) command to deal with each in turn. The next command can also be given a list of file names, or a pattern as used by the shell to specify a new set of files to be dealt with.
In general, file names in the editor may be formed with full shell metasyntax. The metacharacter `%' is also available in forming file names and is replaced by the name of the current file.
The editor has a group of buffers whose names are the ASCII lower-case letters (a-z). You can place text in these named buffers where it is available to be inserted
elsewhere in the file. The contents of these buffers remain available when you begin editing a new file using the edit (e) command.
There is a command & in ex which repeats the last substitute command. In addition, there is a confirmed substitute command. You give a
range of substitutions to be done and the editor interactively asks whether each substitution is desired.
It is possible to ignore the case of letters in searches and substitutions. ex also allows regular expressions which match words to be constructed. This is convenient, for example,
in searching for the word ``edit'' if your document also contains the word ``editor.''
ex has a set of options which you can set to tailor it to your liking. One option which is very useful is the autoindent option that allows the editor to supply
leading white space to align text automatically. You can then use ^D as a backtab and space or tab to move forward to align new code easily.
Miscellaneous useful features include an intelligent join (j) command that supplies white space between joined lines automatically, commands <
and > which shift groups of lines, and the ability to filter portions of the buffer through commands such as sort.