xref: /freebsd/share/doc/usd/10.exref/exref/ex.rm (revision 924226fba12cc9a228c73b956e1b7fa24c60b055)
Copyright (c) 1980, 1993
The Regents of the University of California. All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. All advertising materials mentioning features or use of this software
must display the following acknowledgement:
This product includes software developed by the University of
California, Berkeley and its contributors.
4. Neither the name of the University nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.

@(#)ex.rm 8.5 (Berkeley) 8/18/96
$FreeBSD$

.nr LL 6.5i .nr FL 6.5i .EH 'USD:12-%''Ex Reference Manual' .OH 'Ex Reference Manual''USD:12-%' .ND .nr )P 0 .nr pd \\n()P .nr )P 0 .nr )P \\n(pd ..

.. .bd S B 3 .RP

Ex Reference Manual

Version 3.7 .AU William Joy .AU Mark Horton .AI Computer Science Division Department of Electrical Engineering and Computer Science University of California, Berkeley Berkeley, Ca. 94720 .AB Ex a line oriented text editor, which supports both command and display oriented editing. This reference manual describes the command oriented part of ex; the display editing features of ex are described in "An Introduction to Display Editing with Vi." Other documents about the editor include the introduction "Edit: A tutorial", the "Ex/edit Command Summary", and a "Vi Quick Reference" card. .AE Starting ex

.FS The financial support of an \s-2IBM\s0 Graduate Fellowship and the National Science Foundation under grants MCS74-07644-A03 and MCS78-07291 is gratefully acknowledged. .FE Each instance of the editor has a set of options, which can be set to tailor it to your liking. The command edit invokes a version of ex designed for more casual or beginning users by changing the default settings of some of these options. To simplify the description which follows we assume the default settings of the options.

When invoked, ex determines the terminal type from the \s-2TERM\s0 variable in the environment. It there is a \s-2TERMCAP\s0 variable in the environment, and the type of the terminal described there matches the \s-2TERM\s0 variable, then that description is used. Also if the \s-2TERMCAP\s0 variable contains a pathname (beginning with a /) then the editor will seek the description of the terminal in that file (rather than the default /etc/termcap). If there is a variable \s-2EXINIT\s0 in the environment, then the editor will execute the commands in that variable, otherwise if there is a file .exrc in your \s-2HOME\s0 directory ex reads commands from that file, simulating a source command. Option setting commands placed in \s-2EXINIT\s0 or .exrc will be executed before each editor session.

A command to enter ex has the following prototype:\(dg .FS \(dg Brackets `[' `]' surround optional parameters here. .FE ex [ - ] [ -v ] [ -t tag ] [ -r ] [ -l ] [ -wn ] [ -x ] [ -R ] [ +command ] name ... The most common case edits a single file with no options, i.e.: ex name The - command line option option suppresses all interactive-user feedback and is useful in processing editor scripts in command files. The -v option is equivalent to using vi rather than ex. The -t option is equivalent to an initial tag command, editing the file containing the tag and positioning the editor at its definition. The -r option is used in recovering after an editor or system crash, retrieving the last saved version of the named file or, if no file is specified, typing a list of saved files. The -l option sets up for editing \s-2LISP\s0, setting the showmatch and lisp options. The -w option sets the default window size to n, and is useful on dialups to start in small windows. The -x option causes ex to prompt for a key , which is used to encrypt and decrypt the contents of the file, which should already be encrypted using the same key, see crypt (1). The -R option sets the readonly option at the start. Name arguments indicate files to be edited. An argument of the form +command indicates that the editor should begin by executing the specified command. If command is omitted, then it defaults to ``$'', positioning the editor at the last line of the first file initially. Other useful commands here are scanning patterns of the form ``/pat'' or line numbers, e.g. ``+100'' starting at line 100. File manipulation Current file

Ex is normally editing the contents of a single file, whose name is recorded in the current file name. Ex performs all editing actions in a buffer (actually a temporary file) into which the text of the file is initially read. Changes made to the buffer have no effect on the file being edited unless and until the buffer contents are written out to the file with a write command. After the buffer contents are written, the previous contents of the written file are no longer accessible. When a file is edited, its name becomes the current file name, and its contents are read into the buffer.

The current file is almost always considered to be edited. This means that the contents of the buffer are logically connected with the current file name, so that writing the current buffer contents onto that file, even if it exists, is a reasonable action. If the current file is not edited then ex will not normally write on it if it already exists.* .FS * The file command will say ``[Not edited]'' if the current file is not considered edited. .FE Alternate file

Each time a new value is given to the current file name, the previous current file name is saved as the alternate file name. Similarly if a file is mentioned but does not become the current file, it is saved as the alternate file name. Filename expansion

Filenames within the editor may be specified using the normal shell expansion conventions. In addition, the character `%' in filenames is replaced by the current file name and the character `#' by the alternate file name.\(dg .FS \(dg This makes it easy to deal alternately with two files and eliminates the need for retyping the name supplied on an edit command after a "No write since last change" diagnostic is received. .FE Multiple files and named buffers

If more than one file is given on the command line, then the first file is edited as described above. The remaining arguments are placed with the first file in the "argument list." The current argument list may be displayed with the args command. The next file in the argument list may be edited with the next command. The argument list may also be respecified by specifying a list of names to the next command. These names are expanded, the resulting list of names becomes the new argument list, and ex edits the first file on the list.

For saving blocks of text while editing, and especially when editing more than one file, ex has a group of named buffers. These are similar to the normal buffer, except that only a limited number of operations are available on them. The buffers have names a through z.\(dd .FS \(dd It is also possible to refer to A through Z; the upper case buffers are the same as the lower but commands append to named buffers rather than replacing if upper case names are used. .FE Read only

It is possible to use ex in "read only" mode to look at files that you have no intention of modifying. This mode protects you from accidently overwriting the file. Read only mode is on when the readonly option is set. It can be turned on with the -R command line option, by the view command line invocation, or by setting the readonly option. It can be cleared by setting noreadonly . It is possible to write, even while in read only mode, by indicating that you really know what you are doing. You can write to a different file, or can use the ! form of write, even while in read only mode. Exceptional Conditions Errors and interrupts

When errors occur ex (optionally) rings the terminal bell and, in any case, prints an error diagnostic. If the primary input is from a file, editor processing will terminate. If an interrupt signal is received, ex prints ``Interrupt'' and returns to its command level. If the primary input is a file, then ex will exit when this occurs. Recovering from hangups and crashes

If a hangup signal is received and the buffer has been modified since it was last written out, or if the system crashes, either the editor (in the first case) or the system (after it reboots in the second) will attempt to preserve the buffer. The next time you log in you should be able to recover the work you were doing, losing at most a few lines of changes from the last point before the hangup or editor crash. To recover a file you can use the -r option. If you were editing the file resume, then you should change to the directory where you were when the crash occurred, giving the command ex -r resume After checking that the retrieved file is indeed ok, you can write it over the previous contents of that file.

You will normally get mail from the system telling you when a file has been saved after a crash. The command ex -r will print a list of the files which have been saved for you. (In the case of a hangup, the file will not appear in the list, although it can be recovered.) Editing modes

Ex has five distinct modes. The primary mode is command mode. Commands are entered in command mode when a `:' prompt is present, and are executed each time a complete line is sent. In "text input" mode ex gathers input lines and places them in the file. The append, insert, and change commands use text input mode. No prompt is printed when you are in text input mode. This mode is left by typing a `.' alone at the beginning of a line, and command mode resumes.

The last three modes are open and visual modes, entered by the commands of the same name, and, within open and visual modes "text insertion" mode. Open and visual modes allow local editing operations to be performed on the text in the file. The open command displays one line at a time on any terminal while visual works on \s-2CRT\s0 terminals with random positioning cursors, using the screen as a (single) window for file editing changes. These modes are described (only) in "An Introduction to Display Editing with Vi." Command structure

Most command names are English words, and initial prefixes of the words are acceptable abbreviations. The ambiguity of abbreviations is resolved in favor of the more commonly used commands.* .FS * As an example, the command substitute can be abbreviated `s' while the shortest available abbreviation for the set command is `se'. .FE Command parameters

Most commands accept prefix addresses specifying the lines in the file upon which they are to have effect. The forms of these addresses will be discussed below. A number of commands also may take a trailing count specifying the number of lines to be involved in the command.\(dg .FS \(dg Counts are rounded down if necessary. .FE Thus the command ``10p'' will print the tenth line in the buffer while ``delete 5'' will delete five lines from the buffer, starting with the current line.

Some commands take other information or parameters, this information always being given after the command name.\(dd .FS \(dd Examples would be option names in a set command i.e. ``set number'', a file name in an edit command, a regular expression in a substitute command, or a target address for a copy command, i.e. ``1,5 copy 25''. .FE Command variants

A number of commands have two distinct variants. The variant form of the command is invoked by placing an `!' immediately after the command name. Some of the default variants may be controlled by options; in this case, the `!' serves to toggle the default. Flags after commands

The characters `#', `p' and `l' may be placed after many commands.** .FS ** A `p' or `l' must be preceded by a blank or tab except in the single special case `dp'. .FE In this case, the command abbreviated by these characters is executed after the command completes. Since ex normally prints the new current line after each change, `p' is rarely necessary. Any number of `+' or `-' characters may also be given with these flags. If they appear, the specified offset is applied to the current line value before the printing command is executed. Comments

It is possible to give editor commands which are ignored. This is useful when making complex editor scripts for which comments are desired. The comment character is the double quote: ". Any command line beginning with " is ignored. Comments beginning with " may also be placed at the ends of commands, except in cases where they could be confused as part of text (shell escapes and the substitute and map commands). Multiple commands per line

More than one command may be placed on a line by separating each pair of commands by a `|' character. However the global commands, comments, and the shell escape `!' must be the last command on a line, as they are not terminated by a `|'. Reporting large changes

Most commands which change the contents of the editor buffer give feedback if the scope of the change exceeds a threshold given by the report option. This feedback helps to detect undesirably large changes so that they may be quickly and easily reversed with an undo. After commands with more global effect such as global or visual, you will be informed if the net change in the number of lines in the buffer during this command exceeds this threshold. Command addressing Addressing primitives

. 20
The current line. Most commands leave the current line as the last line which they affect. The default address for most commands is the current line, thus `.' is rarely used alone as an address.
n 20
The nth line in the editor's buffer, lines being numbered sequentially from 1.
$ 20
The last line in the buffer.
% 20
An abbreviation for ``1,$'', the entire buffer.
+n -n 20
An offset relative to the current buffer line.\(dg .FS \(dg The forms `.+3' `+3' and `+++' are all equivalent; if the current line is line 100 they all address line 103. .FE
/pat/ ?pat? 20
Scan forward and backward respectively for a line containing pat, a regular expression (as defined below). The scans normally wrap around the end of the buffer. If all that is desired is to print the next line containing pat, then the trailing / or ? may be omitted. If pat is omitted or explicitly empty, then the last regular expression specified is located.\(dd .FS \(dd The forms \e/ and \e? scan using the last regular expression used in a scan; after a substitute // and ?? would scan using the substitute's regular expression. .FE
\(aa\(aa \(aax 20
Before each non-relative motion of the current line `.', the previous current line is marked with a tag, subsequently referred to as `\(aa\(aa'. This makes it easy to refer or return to this previous context. Marks may also be established by the mark command, using single lower case letters x and the marked lines referred to as `\(aax'. Combining addressing primitives

Addresses to commands consist of a series of addressing primitives, separated by `,' or `;'. Such address lists are evaluated left-to-right. When addresses are separated by `;' the current line `.' is set to the value of the previous addressing expression before the next address is interpreted. If more addresses are given than the command requires, then all but the last one or two are ignored. If the command takes two addresses, the first addressed line must precede the second in the buffer.\(dg .FS \(dg Null address specifications are permitted in a list of addresses, the default in this case is the current line `.'; thus `,100' is equivalent to `.,100'. It is an error to give a prefix address to a command which expects none. .FE Command descriptions

The following form is a prototype for all ex commands: address command ! parameters count flags All parts are optional; the degenerate case is the empty command which prints the next line in the file. For sanity with use from within visual mode, ex ignores a ``:'' preceding any command.

In the following command descriptions, the default addresses are shown in parentheses, which are not, however, part of the command. .LC abbreviate word rhs abbr: ab .ZP Add the named abbreviation to the current list. When in input mode in visual, if word is typed as a complete word, it will be changed to rhs . .LC ( . ) append abbr: a

text

\fB. .ZP Reads the input text and places it after the specified line. After the command, `.' addresses the last line input or the specified line if no lines were input. If address `0' is given, text is placed at the beginning of the buffer. .LC a!

text

\fB. .ZP The variant flag to append toggles the setting for the autoindent option during the input of text. .LC args .ZP The members of the argument list are printed, with the current argument delimited by `[' and `]'.

cd directory .ZP The cd command is a synonym for chdir. .. .LC ( . , . ) change count abbr: c

text

\fB. .ZP Replaces the specified lines with the input text. The current line becomes the last line input; if no lines were input it is left as for a delete. .LC c!

text

\fB. .ZP The variant toggles autoindent during the change. .LC chdir directory .ZP The specified directory becomes the current directory. If no directory is specified, the current value of the home option is used as the target directory. After a chdir the current file is not considered to have been edited so that write restrictions on pre-existing files apply. .. .LC ( . , . )\|copy addr flags abbr: co .ZP A copy of the specified lines is placed after addr, which may be `0'. The current line `.' addresses the last line of the copy. The command t is a synonym for copy. .LC ( . , . )\|delete buffer count flags abbr: d .ZP Removes the specified lines from the buffer. The line after the last line deleted becomes the current line; if the lines deleted were originally at the end, the new last line becomes the current line. If a named buffer is specified by giving a letter, then the specified lines are saved in that buffer, or appended to it if an upper case letter is used. .LC edit file abbr: e

ex file .ZP Used to begin an editing session on a new file. The editor first checks to see if the buffer has been modified since the last write command was issued. If it has been, a warning is issued and the command is aborted. The command otherwise deletes the entire contents of the editor buffer, makes the named file the current file and prints the new filename. After insuring that this file is sensible\(dg .FS \(dg I.e., that it is not a binary file such as a directory, a block or character special file other than /dev/tty, a terminal, or a binary or executable file (as indicated by the first word). .FE the editor reads the file into its buffer.

If the read of the file completes without error, the number of lines and characters read is typed. If there were any non-\s-2ASCII\s0 characters in the file they are stripped of their non-\s-2ASCII\s0 high bits, and any null characters in the file are discarded. If none of these errors occurred, the file is considered edited. If the last line of the input file is missing the trailing newline character, it will be supplied and a complaint will be issued. This command leaves the current line `.' at the last line read.\(dd .FS \(dd If executed from within open or visual, the current line is initially the first line of the file. .FE .LC e! file .ZP The variant form suppresses the complaint about modifications having been made and not written from the editor buffer, thus discarding all changes which have been made before editing the new file. .LC e +n file .ZP Causes the editor to begin at line n rather than at the last line; n may also be an editor command containing no spaces, e.g.: ``+/pat''. .LC file abbr: f .ZP Prints the current file name, whether it has been `[Modified]' since the last write command, whether it is "read only" , the current line, the number of lines in the buffer, and the percentage of the way through the buffer of the current line.* .FS * In the rare case that the current file is `[Not edited]' this is noted also; in this case you have to use the form w! to write to the file, since the editor is not sure that a write will not destroy a file unrelated to the current contents of the buffer. .FE .LC file file .ZP The current file name is changed to file which is considered `[Not edited]'. .LC ( 1 , $ ) global /pat\|/ cmds abbr: g .ZP First marks each line among those specified which matches the given regular expression. Then the given command list is executed with `.' initially set to each marked line.
The command list consists of the remaining commands on the current input line and may continue to multiple lines by ending all but the last such line with a `\e'. If cmds (and possibly the trailing / delimiter) is omitted, each line matching pat is printed. Append, insert, and change commands and associated input are permitted; the `.' terminating input may be omitted if it would be on the last line of the command list. Open and visual commands are permitted in the command list and take input from the terminal.
The global command itself may not appear in cmds. The undo command is also not permitted there, as undo instead can be used to reverse the entire global command. The options autoprint and autoindent are inhibited during a global, (and possibly the trailing / delimiter) and the value of the report option is temporarily infinite, in deference to a report for the entire global. Finally, the context mark `\'\'' is set to the value of `.' before the global command begins and is not changed during a global command, except perhaps by an open or visual within the global. .LC g! /pat/ cmds abbr: v
The variant form of global runs cmds at each line not matching pat. .LC ( . )\|insert abbr: i

text

\fB. .ZP Places the given text before the specified line. The current line is left at the last line input; if there were none input it is left at the line before the addressed line. This command differs from append only in the placement of text. .KS .LC i!

text

\fB. .ZP The variant toggles autoindent during the insert. .KE .LC ( . , .+1 ) join count flags abbr: j .ZP Places the text from a specified range of lines together on one line. White space is adjusted at each junction to provide at least one blank character, two if there was a `.' at the end of the line, or none if the first following character is a `)'. If there is already white space at the end of the line, then the white space at the start of the next line will be discarded. .LC j! .ZP The variant causes a simpler join with no white space processing; the characters in the lines are simply concatenated. .LC ( . ) k x .ZP The k command is a synonym for mark. It does not require a blank or tab before the following letter. .LC ( . , . ) list count flags .ZP Prints the specified lines in a more unambiguous way: tabs are printed as `^I' and the end of each line is marked with a trailing `$'. The current line is left at the last line printed. .LC map lhs rhs .ZP The map command is used to define macros for use in visual mode. Lhs should be a single character, or the sequence ``#n'', for n a digit, referring to function key n. When this character or function key is typed in visual mode, it will be as though the corresponding rhs had been typed. On terminals without function keys, you can type ``#n''. See section 6.9 of the ``Introduction to Display Editing with Vi'' for more details. .LC ( . ) mark x .ZP Gives the specified line mark x, a single lower case letter. The x must be preceded by a blank or a tab. The addressing form `\'x' then addresses this line. The current line is not affected by this command. .LC ( . , . ) move addr abbr: m .ZP The move command repositions the specified lines to be after addr . The first of the moved lines becomes the current line. .LC next abbr: n .ZP The next file from the command line argument list is edited. .LC n! .ZP The variant suppresses warnings about the modifications to the buffer not having been written out, discarding (irretrievably) any changes which may have been made. .LC n filelist

n +command filelist .ZP The specified filelist is expanded and the resulting list replaces the current argument list; the first file in the new list is then edited. If command is given (it must contain no spaces), then it is executed after editing the first such file. .LC ( . , . ) number count flags abbr: # or nu .ZP Prints each specified line preceded by its buffer line number. The current line is left at the last line printed. .KS .LC ( . ) open flags abbr: o

( . ) open /pat\|/ flags .ZP Enters intraline editing open mode at each addressed line. If pat is given, then the cursor will be placed initially at the beginning of the string matched by the pattern. To exit this mode use Q. See "An Introduction to Display Editing with Vi" for more details. .KE .LC preserve .ZP The current editor buffer is saved as though the system had just crashed. This command is for use only in emergencies when a write command has resulted in an error and you don't know how to save your work. After a preserve you should seek help. .LC ( . , . )\|print count abbr: p or P .ZP Prints the specified lines with non-printing characters printed as control characters `^x\|'; delete (octal 177) is represented as `^?'. The current line is left at the last line printed. .LC ( . )\|put buffer abbr: pu .ZP Puts back previously deleted or yanked lines. Normally used with delete to effect movement of lines, or with yank to effect duplication of lines. If no buffer is specified, then the last deleted or yanked text is restored.* .FS * But no modifying commands may intervene between the delete or yank and the put, nor may lines be moved between files without using a named buffer. .FE By using a named buffer, text may be restored that was saved there at any previous time. .LC quit abbr: q .ZP Causes ex to terminate. No automatic write of the editor buffer to a file is performed. However, ex issues a warning message if the file has changed since the last write command was issued, and does not quit.\(dg .FS \(dg Ex will also issue a diagnostic if there are more files in the argument list. .FE Normally, you will wish to save your changes, and you should give a write command; if you wish to discard them, use the q! command variant. .LC q! .ZP Quits from the editor, discarding changes to the buffer without complaint. .LC ( . ) read file abbr: r .ZP Places a copy of the text of the given file in the editing buffer after the specified line. If no file is given the current file name is used. The current file name is not changed unless there is none in which case file becomes the current name. The sensibility restrictions for the edit command apply here also. If the file buffer is empty and there is no current name then ex treats this as an edit command.

Address `0' is legal for this command and causes the file to be read at the beginning of the buffer. Statistics are given as for the edit command when the read successfully terminates. After a read the current line is the last line read.\(dd .FS \(dd Within open and visual the current line is set to the first line read rather than the last. .FE .LC ( . ) read !command .ZP Reads the output of the command command into the buffer after the specified line. This is not a variant form of the command, rather a read specifying a command rather than a filename; a blank or tab before the ! is mandatory. .LC recover file .ZP Recovers file from the system save area. Used after a accidental hangup of the phone** .FS ** The system saves a copy of the file you were editing only if you have made changes to the file. .FE or a system crash** or preserve command. Except when you use preserve you will be notified by mail when a file is saved. .LC rewind abbr: rew .ZP The argument list is rewound, and the first file in the list is edited. .LC rew! .ZP Rewinds the argument list discarding any changes made to the current buffer. .LC set parameter .ZP With no arguments, prints those options whose values have been changed from their defaults; with parameter all it prints all of the option values.
Giving an option name followed by a `?' causes the current value of that option to be printed. The `?' is unnecessary unless the option is Boolean valued. Boolean options are given values either by the form `set option' to turn them on or `set nooption' to turn them off; string and numeric options are assigned via the form `set option=value'.
More than one parameter may be given to set \|; they are interpreted left-to-right. .LC shell abbr: sh
A new shell is created. When it terminates, editing resumes. .LC source file abbr: so
Reads and executes commands from the specified file. Source commands may be nested. .LC ( . , . ) substitute /pat\|/repl\|/ options count flags abbr: s
On each specified line, the first instance of pattern pat is replaced by replacement pattern repl. If the global indicator option character `g' appears, then all instances are substituted; if the confirm indication character `c' appears, then before each substitution the line to be substituted is typed with the string to be substituted marked with `\(ua' characters. By typing an `y' one can cause the substitution to be performed, any other input causes no change to take place. After a substitute the current line is the last line substituted.
Lines may be split by substituting new-line characters into them. The newline in repl must be escaped by preceding it with a `\e'. Other metacharacters available in pat and repl are described below. .LC stop .ZP Suspends the editor, returning control to the top level shell. If autowrite is set and there are unsaved changes, a write is done first unless the form stop ! is used. This commands is only available where supported by the teletype driver and operating system. .LC ( . , . ) substitute options count flags abbr: s .ZP If pat and repl are omitted, then the last substitution is repeated. This is a synonym for the & command. .LC ( . , . ) t addr flags .ZP The t command is a synonym for copy . .LC ta tag .ZP The focus of editing switches to the location of tag, switching to a different line in the current file where it is defined, or if necessary to another file.\(dd .FS \(dd If you have modified the current file before giving a tag command, you must write it out; giving another tag command, specifying no tag will reuse the previous tag. .FE
The tags file is normally created by a program such as ctags, and consists of a number of lines with three fields separated by blanks or tabs. The first field gives the name of the tag, the second the name of the file where the tag resides, and the third gives an addressing form which can be used by the editor to find the tag; this field is usually a contextual scan using `/pat/' to be immune to minor changes in the file. Such scans are always performed as if nomagic was set.

The tag names in the tags file must be sorted alphabetically. .LC unabbreviate word abbr: una .ZP Delete word from the list of abbreviations. .LC undo abbr: u .ZP Reverses the changes made in the buffer by the last buffer editing command. Note that global commands are considered a single command for the purpose of undo (as are open and visual.) Also, the commands write and edit which interact with the file system cannot be undone. Undo is its own inverse.

Undo always marks the previous value of the current line `.' as `\'\''. After an undo the current line is the first line restored or the line before the first line deleted if no lines were restored. For commands with more global effect such as global and visual the current line regains it's pre-command value after an undo. .LC unmap lhs .ZP The macro expansion associated by map for lhs is removed. .LC ( 1 , $ ) v /pat\|/ cmds .ZP A synonym for the global command variant g!, running the specified cmds on each line which does not match pat. .LC version abbr: ve .ZP Prints the current version number of the editor as well as the date the editor was last changed. .LC ( . ) visual type count flags abbr: vi .ZP Enters visual mode at the specified line. Type is optional and may be `-' , `\(ua' or `.' as in the z command to specify the placement of the specified line on the screen. By default, if type is omitted, the specified line is placed as the first on the screen. A count specifies an initial window size; the default is the value of the option window. See the document "An Introduction to Display Editing with Vi" for more details. To exit this mode, type Q. .LC visual file

visual +n file .ZP From visual mode, this command is the same as edit. .LC ( 1 , $ ) write file abbr: w .ZP Writes changes made back to file, printing the number of lines and characters written. Normally file is omitted and the text goes back where it came from. If a file is specified, then text will be written to that file.* .FS * The editor writes to a file only if it is the current file and is edited , if the file does not exist, or if the file is actually a teletype, /dev/tty, /dev/null. Otherwise, you must give the variant form w! to force the write. .FE If the file does not exist it is created. The current file name is changed only if there is no current file name; the current line is never changed.

If an error occurs while writing the current and edited file, the editor considers that there has been ``No write since last change'' even if the buffer had not previously been modified. .LC ( 1 , $ ) write>> file abbr: w>> .ZP Writes the buffer contents at the end of an existing file.
.LC w! name .ZP Overrides the checking of the normal write command, and will write to any file which the system permits. .LC ( 1 , $ ) w !command .ZP Writes the specified lines into command. Note the difference between w! which overrides checks and w ! which writes to a command. .LC wq name .ZP Like a write and then a quit command. .LC wq! name .ZP The variant overrides checking on the sensibility of the write command, as w! does. .LC xit name .ZP If any changes have been made and not written, writes the buffer out. Then, in any case, quits. .LC ( . , . )\|yank buffer count abbr: ya .ZP Places the specified lines in the named buffer, for later retrieval via put. If no buffer name is specified, the lines go to a more volatile place; see the put command description. .LC ( .+1 ) z count .ZP Print the next count lines, default window. .LC ( . ) z type count .ZP Prints a window of text with the specified line at the top. If type is `-' the line is placed at the bottom; a `.' causes the line to be placed in the center.* A count gives the number of lines to be displayed rather than double the number specified by the scroll option. On a \s-2CRT\s0 the screen is cleared before display begins unless a count which is less than the screen size is given. The current line is left at the last line printed. .FS * Forms `z=' and `z\(ua' also exist; `z=' places the current line in the center, surrounds it with lines of `-' characters and leaves the current line at this line. The form `z\(ua' prints the window before `z-' would. The characters `+', `\(ua' and `-' may be repeated for cumulative effect. On some v2 editors, no type may be given. .FE .LC ! command .ZP The remainder of the line after the `!' character is sent to a shell to be executed. Within the text of command the characters `%' and `#' are expanded as in filenames and the character `!' is replaced with the text of the previous command. Thus, in particular, `!!' repeats the last such shell escape. If any such expansion is performed, the expanded line will be echoed. The current line is unchanged by this command.
If there has been ``[No write]'' of the buffer contents since the last change to the editing buffer, then a diagnostic will be printed before the command is executed as a warning. A single `!' is printed when the command completes. .LC ( addr , addr ) ! command .ZP Takes the specified address range and supplies it as standard input to command; the resulting output then replaces the input lines. .LC ( $ ) = .ZP Prints the line number of the addressed line. The current line is unchanged. .KS .LC ( . , . ) > count flags

( . , . ) < count flags

Perform intelligent shifting on the specified lines; < shifts left and > shift right. The quantity of shift is determined by the shiftwidth option and the repetition of the specification character. Only white space (blanks and tabs) is shifted; no non-white characters are discarded in a left-shift. The current line becomes the last line which changed due to the shifting. .KE .LC ^D .ZP An end-of-file from a terminal input scrolls through the file. The scroll option specifies the size of the scroll, normally a half screen of text. .LC ( .+1 , .+1 )

( .+1 , .+1 ) | .ZP An address alone causes the addressed lines to be printed. A blank line prints the next line in the file. .LC ( . , . ) & options count flags .ZP Repeats the previous substitute command. .LC ( . , . ) \s+2~\s0 options count flags .ZP Replaces the previous regular expression with the previous replacement pattern from a substitution. Regular expressions and substitute replacement patterns Regular expressions

A regular expression specifies a set of strings of characters. A member of this set of strings is said to be matched by the regular expression. Ex remembers two previous regular expressions: the previous regular expression used in a substitute command and the previous regular expression used elsewhere (referred to as the previous scanning regular expression.) The previous regular expression can always be referred to by a null re, e.g. `//' or `??'. Magic and nomagic

The regular expressions allowed by ex are constructed in one of two ways depending on the setting of the magic option. The ex and vi default setting of magic gives quick access to a powerful set of regular expression metacharacters. The disadvantage of magic is that the user must remember that these metacharacters are magic and precede them with the character `\e' to use them as ``ordinary'' characters. With nomagic, the default for edit, regular expressions are much simpler, there being only two metacharacters. The power of the other metacharacters is still available by preceding the (now) ordinary character with a `\e'. Note that `\e' is thus always a metacharacter.

The remainder of the discussion of regular expressions assumes that that the setting of this option is magic.\(dg .FS \(dg To discern what is true with nomagic it suffices to remember that the only special characters in this case will be `\(ua' at the beginning of a regular expression, `$' at the end of a regular expression, and `\e'. With nomagic the characters `\s+2~\s0' and `&' also lose their special meanings related to the replacement pattern of a substitute. .FE Basic regular expression summary

The following basic constructs are used to construct magic mode regular expressions.

char 15
An ordinary character matches itself. The characters `\(ua' at the beginning of a line, `$' at the end of line, `*' as any character other than the first, `.', `\e', `[', and `\s+2~\s0' are not ordinary characters and must be escaped (preceded) by `\e' to be treated as such.
\(ua
At the beginning of a pattern forces the match to succeed only at the beginning of a line.
$
At the end of a regular expression forces the match to succeed only at the end of the line.
\fB.
Matches any single character except the new-line character.
\e<
Forces the match to occur only at the beginning of a ``variable'' or ``word''; that is, either at the beginning of a line, or just before a letter, digit, or underline and after a character not one of these.
\e>
Similar to `\e<', but matching the end of a ``variable'' or ``word'', i.e. either the end of the line or before character which is neither a letter, nor a digit, nor the underline character.
[string]
Matches any (single) character in the class defined by string. Most characters in string define themselves. A pair of characters separated by `-' in string defines the set of characters collating between the specified lower and upper bounds, thus `[a-z]' as a regular expression matches any (single) lower-case letter. If the first character of string is an `\(ua' then the construct matches those characters which it otherwise would not; thus `[\(uaa-z]' matches anything but a lower-case letter (and of course a newline). To place any of the characters `\(ua', `[', or `-' in string you must escape them with a preceding `\e'. Combining regular expression primitives

The concatenation of two regular expressions matches the leftmost and then longest string which can be divided with the first piece matching the first regular expression and the second piece matching the second. Any of the (single character matching) regular expressions mentioned above may be followed by the character `*' to form a regular expression which matches any number of adjacent occurrences (including 0) of characters matched by the regular expression it follows.

The character `\s+2~\s0' may be used in a regular expression, and matches the text which defined the replacement part of the last substitute command. A regular expression may be enclosed between the sequences `\e(' and `\e)' with side effects in the substitute replacement patterns. Substitute replacement patterns

The basic metacharacters for the replacement pattern are `&' and `~'; these are given as `\e&' and `\e~' when nomagic is set. Each instance of `&' is replaced by the characters which the regular expression matched. The metacharacter `~' stands, in the replacement pattern, for the defining text of the previous replacement pattern.

Other metasequences possible in the replacement pattern are always introduced by the escaping character `\e'. The sequence `\en' is replaced by the text matched by the n-th regular subexpression enclosed between `\e(' and `\e)'.\(dg .FS \(dg When nested, parenthesized subexpressions are present, n is determined by counting occurrences of `\e(' starting from the left. .FE The sequences `\eu' and `\el' cause the immediately following character in the replacement to be converted to upper- or lower-case respectively if this character is a letter. The sequences `\eU' and `\eL' turn such conversion on, either until `\eE' or `\ee' is encountered, or until the end of the replacement pattern.

.. Option descriptions

.LC autoindent, ai default: noai .ZP Can be used to ease the preparation of structured program text. At the beginning of each append , change or insert command or when a new line is opened or created by an append , change , insert , or substitute operation within open or visual mode, ex looks at the line being appended after, the first line changed or the line inserted before and calculates the amount of white space at the start of the line. It then aligns the cursor at the level of indentation so determined.

If the user then types lines of text in, they will continue to be justified at the displayed indenting level. If more white space is typed at the beginning of a line, the following line will start aligned with the first non-white character of the previous line. To back the cursor up to the preceding tab stop one can hit ^D. The tab stops going backwards are defined at multiples of the shiftwidth option. You cannot backspace over the indent, except by sending an end-of-file with a ^D.
Specially processed in this mode is a line with no characters added to it, which turns into a completely blank line (the white space provided for the autoindent is discarded.) Also specially processed in this mode are lines beginning with an `\(ua' and immediately followed by a ^D. This causes the input to be repositioned at the beginning of the line, but retaining the previous indent for the next line. Similarly, a `0' followed by a ^D repositions at the beginning but without retaining the previous indent.
Autoindent doesn't happen in global commands or when the input is not a terminal. .LC autoprint, ap default: ap .ZP Causes the current line to be printed after each delete , copy , join , move , substitute , t , undo or shift command. This has the same effect as supplying a trailing `p' to each such command. Autoprint is suppressed in globals, and only applies to the last of many commands on a line. .LC autowrite, aw default: noaw .ZP Causes the contents of the buffer to be written to the current file if you have modified it and give a next, rewind, stop, tag, or ! command, or a ^\(ua (switch files) or ^] (tag goto) command in visual. Note, that the edit and ex commands do not autowrite. In each case, there is an equivalent way of switching when autowrite is set to avoid the autowrite (edit for next , rewind! for .I rewind , stop! for stop , tag! for tag , shell for ! , and :e # and a :ta! command from within visual). .LC beautify, bf default: nobeautify .ZP Causes all control characters except tab, newline and form-feed to be discarded from the input. A complaint is registered the first time a backspace character is discarded. Beautify does not apply to command input. .LC directory, dir default: dir=/tmp .ZP Specifies the directory in which ex places its buffer file. If this directory in not writable, then the editor will exit abruptly when it fails to be able to create its buffer there. .LC edcompatible default: noedcompatible .ZP Causes the presence of absence of g and c suffixes on substitute commands to be remembered, and to be toggled by repeating the suffices. The suffix r makes the substitution be as in the ~ command, instead of like &. .LC errorbells, eb default: noeb .ZP Error messages are preceded by a bell.* .FS * Bell ringing in open and visual on errors is not suppressed by setting noeb. .FE If possible the editor always places the error message in a standout mode of the terminal (such as inverse video) instead of ringing the bell. .LC hardtabs, ht default: ht=8 .ZP Gives the boundaries on which terminal hardware tabs are set (or on which the system expands tabs). .LC ignorecase, ic default: noic .ZP All upper case characters in the text are mapped to lower case in regular expression matching. In addition, all upper case characters in regular expressions are mapped to lower case except in character class specifications. .LC lisp default: nolisp .ZP Autoindent indents appropriately for lisp code, and the ( ) { } [[ and ]] commands in open and visual are modified to have meaning for lisp. .LC list default: nolist .ZP All printed lines will be displayed (more) unambiguously, showing tabs and end-of-lines as in the list command. .LC magic default: magic for ex and vi\(dg .FS \(dg Nomagic for edit. .FE .ZP If nomagic is set, the number of regular expression metacharacters is greatly reduced, with only `\(ua' and `$' having special effects. In addition the metacharacters `~' and `&' of the replacement pattern are treated as normal characters. All the normal metacharacters may be made magic when nomagic is set by preceding them with a `\e'. .LC mesg default: mesg .ZP Causes write permission to be turned off to the terminal while you are in visual mode, if nomesg is set. .LC modeline default: nomodeline .ZP If modeline is set, then the first 5 lines and the last five lines of the file will be checked for ex command lines and the comands issued. To be recognized as a command line, the line must have the string ex: or vi: preceeded by a tab or a space. This string may be anywhere in the line and anything after the : is interpeted as editor commands. This option defaults to off because of unexpected behavior when editting files such as /etc/passwd. .LC number, nu default: nonumber .ZP Causes all output lines to be printed with their line numbers. In addition each input line will be prompted for by supplying the line number it will have. .LC open default: open .ZP If noopen, the commands open and visual are not permitted. This is set for edit to prevent confusion resulting from accidental entry to open or visual mode. .LC optimize, opt default: optimize .ZP Throughput of text is expedited by setting the terminal to not do automatic carriage returns when printing more than one (logical) line of output, greatly speeding output on terminals without addressable cursors when text with leading white space is printed. .LC paragraphs, para default: para=IPLPPPQPP\0LIbp .ZP Specifies the paragraphs for the { and } operations in open and visual. The pairs of characters in the option's value are the names of the macros which start paragraphs. .LC prompt default: prompt .ZP Command mode input is prompted for with a `:'. .LC redraw default: noredraw .ZP The editor simulates (using great amounts of output), an intelligent terminal on a dumb terminal (e.g. during insertions in visual the characters to the right of the cursor position are refreshed as each input character is typed.) Useful only at very high speed. .LC remap default: remap .ZP If on, macros are repeatedly tried until they are unchanged. For example, if o is mapped to O , and O is mapped to I , then if remap is set, o will map to I , but if noremap is set, it will map to O . .LC report default: report=5\(dg .FS \(dg 2 for edit. .FE .ZP Specifies a threshold for feedback from commands. Any command which modifies more than the specified number of lines will provide feedback as to the scope of its changes. For commands such as global , open , undo , and visual which have potentially more far reaching scope, the net change in the number of lines in the buffer is presented at the end of the command, subject to this same threshold. Thus notification is suppressed during a global command on the individual commands performed. .LC scroll default: scroll=\(12 window .ZP Determines the number of logical lines scrolled when an end-of-file is received from a terminal input in command mode, and the number of lines printed by a command mode z command (double the value of scroll ). .LC sections default: sections=SHNHH\0HU .ZP Specifies the section macros for the [[ and ]] operations in open and visual. The pairs of characters in the options's value are the names of the macros which start paragraphs. .LC shell, sh default: sh=/bin/sh .ZP Gives the path name of the shell forked for the shell escape command `!', and by the shell command. The default is taken from SHELL in the environment, if present. .LC shiftwidth, sw default: sw=8 .ZP Gives the width a software tab stop, used in reverse tabbing with ^D when using autoindent to append text, and by the shift commands. .LC showmatch, sm default: nosm .ZP In open and visual mode, when a ) or } is typed, move the cursor to the matching ( or { for one second if this matching character is on the screen. Extremely useful with lisp. .LC slowopen, slow terminal dependent .ZP Affects the display algorithm used in visual mode, holding off display updating during input of new text to improve throughput when the terminal in use is both slow and unintelligent. See "An Introduction to Display Editing with Vi" for more details. .LC tabstop, ts default: ts=8 .ZP The editor expands tabs in the input file to be on tabstop boundaries for the purposes of display. .LC taglength, tl default: tl=0 .ZP Tags are not significant beyond this many characters. A value of zero (the default) means that all characters are significant. .LC tags default: tags=tags /usr/lib/tags .ZP A path of files to be used as tag files for the tag command. A requested tag is searched for in the specified files, sequentially. By default, files called tags are searched for in the current directory and in /usr/lib (a master file for the entire system). .LC term from environment TERM .ZP The terminal type of the output device. .LC terse default: noterse .ZP Shorter error diagnostics are produced for the experienced user. .LC warn default: warn .ZP Warn if there has been `[No write since last change]' before a `!' command escape. .LC window default: window=speed dependent .ZP The number of lines in a text window in the visual command. The default is 8 at slow speeds (600 baud or less), 16 at medium speed (1200 baud), and the full screen (minus one line) at higher speeds. .LC w300, w1200\, w9600 .ZP These are not true options but set window only if the speed is slow (300), medium (1200), or high (9600), respectively. They are suitable for an EXINIT and make it easy to change the 8/16/full screen rule. .LC wrapscan, ws default: ws .ZP Searches using the regular expressions in addressing will wrap around past the end of the file. .LC wrapmargin, wm default: wm=0 .ZP Defines a margin for automatic wrapover of text during input in open and visual modes. See "An Introduction to Text Editing with Vi" for details. .LC writeany, wa default: nowa
Inhibit the checks normally made before write commands, allowing a write to any file which the system protection mechanism will allow. Acknowledgements

Chuck Haley contributed greatly to the early development of ex. Bruce Englar encouraged the redesign which led to ex version 1. Bill Joy wrote versions 1 and 2.0 through 2.7, and created the framework that users see in the present editor. Mark Horton added macros and other features and made the editor work on a large number of terminals and Unix systems.