1 Ex Description
The following words have special meanings for commands.

<end-of-file>
    The end-of-file character is used to scroll the screen in the editor. This character is normally However, whatever character is set for the current terminal is supported as well as

line
    A single-line address, given in any of the forms described in the section entitled The default for is the current line.

range
    A line, or a pair of line addresses, separated by a comma or semicolon. (See the section entitled for more information.) The default for range is the current line i.e. A percent sign stands for the range The starting address must be less than, or equal to, the ending address.

count
    A positive integer, specifying the number of lines to be affected by the command; the default is 1. Generally, a count past the end-of-file may be specified, e.g. the command in a 10 line file is acceptable, and will print from the current line through the last line in the file.

flags
    One or more of the characters and When a command that accepts these flags completes, the addressed line(s) are written out as if by the corresponding or commands. In addition, any number of or characters can be specified before, after, or during the flags, in which case the line written is not necessarily the one affected by the command, but rather the line addressed by the offset address specified. The default for is none.

file
    A pattern used to derive a pathname; the default is the current file. File names are subjected to normal word expansions. Anywhere a file name is specified, it is also possible to use the special string This will be replaced with a temporary file name which can be used for temporary work, e.g. creates and edits a new file. If both a count and a range are specified for commands that use either, the starting line for the command is the line addressed by the range, and subsequent lines are affected by the command, e.g. the command prints out lines 3, 4, 5 and 6. When only a line or range is specified, with no command, the implied command is either a or command. The command used is the most recent of the three commands to have been used (including any use as a flag). If none of these commands have been used before, the command is the implied command. When no range or count is specified and the command line is a blank line, the current line is incremented by 1 and then the current line is displayed. Zero or more whitespace characters may precede or follow the addresses, count, flags, or command name. Any object following a command name (such as buffer, file, etc.), that begins with an alphabetic character, should be separated from the command name by at least one whitespace character. Any character, including and retain their literal value when preceded by a backslash.

1 Ex Commands
The following section describes the commands available in the editor. In each entry below, the tag line is a usage synopsis for the command. Each command can be entered as the abbreviation (those characters in the synopsis command word preceding the character), the full command (all characters shown for the command word, omitting the and characters), or any leading subset of the full command down to the abbreviation. For example, the args command (shown as in the synopsis) can be entered as or Each command described below notes the new current line after it is executed, as well as any options that affect the command.

"   A comment. Command lines beginning with the double-quote character are ignored. This permits comments in editor scripts and startup files.

<control-D>

<end-of-file>
    Scroll the screen. Write the next N lines, where N is the value of the [scroll] option. The command is the end-of-file terminal character, which may be different on different terminals. Traditionally, it is the key.

    Historically, the command ignored any preceding count, and the character was ignored unless it was entered as the first character of the command. This implementation treats it as a command if entered as the first character of the command line, and otherwise treats it as any other character.

  Set to the last line written.
Affected by the [scroll] option.

! argument(s)

[range]! argument(s)
    Execute a shell command, or filter lines through a shell command. In the first synopsis, the remainder of the line after the character is passed to the program named by the [shell] option, as a single argument.

    Within the rest of the line, and are expanded into the current and alternate pathnames, respectively. The character is expanded with the command text of the previous command. (Therefore, the command repeats the previous command.) The special meanings of and can be overridden by escaping them with a backslash. If no or command has yet been executed, it is an error to use an unescaped character. The command does do shell expansion on the strings provided as arguments. If any of the above expansions change the command the user entered, the command is redisplayed at the bottom of the screen.

    then executes the program named by the [shell] option, with a flag followed by the arguments (which are bundled into a single argument).

    The command is permitted in an empty file.

    If the file has been modified since it was last completely written, the command will warn you.

    A single character is displayed when the command completes.

    In the second form of the command, the remainder of the line after the is passed to the program named by the [shell] option, as described above. The specified lines are passed to the program as standard input, and the standard and standard error output of the program replace the original lines.

  Unchanged if no range was specified, otherwise set to the first
line of the range. Affected by the [shell] and [warn] options.

[range] # [count] [flags]

[range] nu[mber] [count] [flags]
    Display the selected lines, each preceded with its line number.

    The line number format is followed by two spaces.

  Set to the last line displayed.
Affected by the [list] option.

@ buffer

* buffer
    Execute a buffer. Each line in the named buffer is executed as an command. If no buffer is specified, or if the specified buffer is or the last buffer executed is used.

[range] <[< ...] [count] [flags]
    Shift lines left or right. The specified lines are shifted to the left (for the command) or right (for the command), by the number of columns specified by the [shiftwidth] option. Only leading whitespace characters are deleted when shifting left; once the first column of the line contains a nonblank character, the command will succeed, but the line will not be modified.

    If the command character or is repeated more than once, the command is repeated once for each additional command character.

  If the current line is set to one of the lines that are affected
by the command, it is unchanged. Otherwise, it is set to the first nonblank character of the lowest numbered line shifted. Affected by the [shiftwidth] option.

[line] = [flags]
    Display the line number of (which defaults to the last line in the file).

  Unchanged.
None.

[range] >[> ...] [count] [flags]
    Shift right. The specified lines are shifted to the right by the number of columns specified by the [shiftwidth] option, by inserting tab and space characters. Empty lines are not changed.

    If the command character is repeated more than once, the command is repeated once for each additional command character.

  Set to the last line modified by the command.
Affected by the [shiftwidth] option.

ab[brev] lhs rhs
    Add an abbreviation to the current abbreviation list. When inserting text in each time a non-word character is entered after a word character, a set of characters ending at the word character are checked for a match with If a match is found, they are replaced with The set of characters that are checked for a match are defined as follows, for inexplicable historical reasons. If only one or two characters were entered before the non-word character that triggered the check, and after the beginning of the insertion, or the beginning of the line or the file, or the last character that was entered, then the one or the both characters are checked for a match. Otherwise, the set includes both characters, as well as the characters that precede them that are the same word class (i.e. word or non-word) as the to last character entered before the non-word character that triggered the check, back to the first the beginning of the insertion, or the beginning of the line or the file.

    For example, the abbreviations:

    :abbreviate | abc | ABC
    :abbreviate | #i | #include
    :abbreviate | /*#i | /*#include
    will all work, while the abbreviations:

    :abbreviate | a#i | A#include
    :abbreviate | /* | /********************
    will not work, and are not permitted by

    To keep the abbreviation expansion from happening, the character immediately following the characters should be quoted with a character.

    The replacement is itself subject to both further abbreviation expansion and further map expansion.

  Unchanged.
None.

[line] a[ppend][!]
    The input text is appended to the specified line. If line 0 is specified, the text is inserted at the beginning of the file. Set to the last line input. If no lines are input, then set to or to the first line of the file if a of 0 was specified. Following the command name with a character causes the [autoindent] option to be toggled for the duration of the command.

  Unchanged.
Affected by the [autoindent] and [number] options.

ar[gs]
    Display the argument list. The current argument is displayed inside of and characters. The argument list is the list of operands specified on startup, which can be replaced using the command.

  Unchanged.
None.

bg  mode only. Background the current screen. The screen is unchanged, but is no longer accessible and disappears from the display. Use the command to bring the screen back to the display foreground.

  Set to the current line when the screen was last edited.
None.

[range] c[hange][!] [count]
    Replace the lines with input text. Following the command name with a character causes the [autoindent] option to be toggled for the duration of the command.

  Set to the last line input, or, if no lines were input,
set to the line before the target line, or to the first line of the file if there are no lines preceding the target line. Affected by the [autoindent] and [number] options.

chd[ir][!] [directory]

cd[!] [directory]
    Change the current working directory. The argument is subjected to word expansions. When invoked with no directory argument and the environment variable is set, the directory named by the environment variable becomes the new current directory. Otherwise, the new current directory becomes the directory returned by the routine.

    The command will fail if the file has been modified since the last complete write of the file. You can override this check by appending a character to the command.

  Unchanged.
Affected by the [cdpath] option.

[range] co[py] line [flags]

[range] t line [flags]
    Copy the specified lines (range) after the destination line. Line 0 may be specified to insert the lines at the beginning of the file.

  Unchanged.
None.

cs[cope] command [args]
    Execute a command. For more information, see the section of the reference manual entitled

[range] d[elete] [buffer] [count] [flags]
    Delete the lines from the file. The deleted text is saved in the specified buffer, or, if no buffer is specified, in the unnamed buffer. If the command name is followed by a letter that could be interpreted as either a buffer name or a flag value (because neither a or values were given), treats the letter as a value if the letter immediately follows the command name, without any whitespace separation. If the letter is preceded by whitespace characters, it treats it as a buffer name.

  Set to the line following the deleted lines,
or to the last line if the deleted lines were at the end. None.

di[splay] b[uffers] | c[onnections] | s[creens] | t[ags]
    Display buffers, connections, screens or tags. The command takes one of three additional arguments, which are as follows:

  Display all buffers (including named, unnamed, and numeric)
that contain text. Display the source directories for all attached databases. Display the file names of all background screens. Display the tags stack.

  Unchanged.
None.

e[dit][!] [+cmd] [file]

ex[!] [+cmd] [file]
    Edit a different file. If the current buffer has been modified since the last complete write, the command will fail. You can override this by appending a character to the command name.

    If the option is specified, that command will be executed in the new file. Any command may be used, although the most common use of this feature is to specify a line number or search pattern to set the initial location in the new file.

    Capitalizing the first letter of the command, i.e. or while in mode, will edit the file in a new screen. In this case, any modifications to the current file are ignored.

  If you have previously edited the file, the current line will be set
to your last position in the file. If that position does not exist, or you have not previously edited the file, the current line will be set to the first line of the file if you are in mode, and the last line of the file if you are in None.

exu[sage] [command]
    Display usage for an command. If is specified, a usage statement for that command is displayed. Otherwise, usage statements for all commands are displayed.

  Unchanged.
None.

f[ile] [file]
    Display and optionally change the file name. If a file name is specified, the current pathname is changed to the specified name. The current pathname, the number of lines, and the current position in the file are displayed.

  Unchanged.
None.

fg [name]
    mode only. Foreground the specified screen. If the argument name doesn't exactly match the name of a file displayed by a background screen, it is compared against the last component of each of the file names. If no background screen is specified, the first background screen is foregrounded.

    By default, foregrounding causes the current screen to be swapped with the backgrounded screen. Capitalizing the first letter of the command, i.e. will foreground the backgrounded screen in a new screen instead of swapping it with the current screen.

  Set to the current line when the screen was last edited.
None.

[range] g[lobal] /pattern/ [commands]

[range] v /pattern/ [commands]
    Apply commands to lines matching (or not matching) a pattern. The lines within the given range that match or do not match the given pattern are selected. Then, the specified command(s) are executed with the current line set to each selected line. If no range is specified, the entire file is searched for matching, or not matching, lines.

    Multiple commands can be specified, one per line, by escaping each character with a backslash, or by separating commands with a character. If no commands are specified, the command defaults to the command.

    For the and commands, the input text must be part of the global command line. In this case, the terminating period can be omitted if it ends the commands.

    The command may also be specified as one of the commands. In this mode, input is taken from the terminal. Entering a command in mode causes the next line matching the pattern to be selected and to be reentered, until the list is exhausted.

    The and commands cannot be used as part of these commands.

    The editor options [autoindent ,] [autoprint] and [report] are turned off for the duration of the and commands.

  The last line modified.
Affected by the [ignorecase] and [magic] options. Turns off the [autoindent ,] [autoprint] and [report] options.

he[lp]
    Display a help message.

  Unchanged.
None.

[line] i[nsert][!]
    The input text is inserted before the specified line. Following the command name with a character causes the [autoindent] option setting to be toggled for the duration of this command.

  Set to the last line input; if no lines were input,
set to the line before the target line, or to the first line of the file if there are no lines preceding the target line. Affected by the [autoindent] and [number] options.

[range] j[oin][!] [count] [flags]
    Join lines of text together.

    A specified to the command specifies that the last line of the plus subsequent lines will be joined. (Note, this differs by one from the general rule where only subsequent lines are affected.)

    If the current line ends with a whitespace character, all whitespace is stripped from the next line. Otherwise, if the next line starts with a open parenthesis do nothing. Otherwise, if the current line ends with a question mark period or exclamation point insert two spaces. Otherwise, insert a single space.

    Appending a character to the command name causes a simpler join with no white-space processing.

  Unchanged.
None.

[range] l[ist] [count] [flags]
    Display the lines unambiguously. Tabs are displayed as and the end of the line is marked with a character.

  Set to the last line displayed.
Affected by the [number] option.

map[!] [lhs rhs]
    Define or display maps (for only).

    If and are not specified, the current set of command mode maps are displayed. If a character is appended to to the command, the text input mode maps are displayed.

    Otherwise, when the character sequence is entered in the action is as if the corresponding had been entered. If a character is appended to the command name, the mapping is effective during text input mode, otherwise, it is effective during command mode. This allows to have two different macro definitions at the same time: one for command mode and one for input mode.

    Whitespace characters require escaping with a character to be entered in the string in visual mode.

    Normally, keys in the string are remapped (see the [remap] option), and it is possible to create infinite loops. However, keys which map to themselves are not further remapped, regardless of the setting of the [remap] option. For example, the command maps the key to the and commands.

    To exit an infinitely looping map, use the terminal character.

  Unchanged.
Affected by the [remap] option.

[line] ma[rk] <character>

[line] k <character>
    Mark the line with the mark The expressions and can then be used as an address in any command that uses one.

  Unchanged.
None.

[range] m[ove] line
    Move the specified lines after the target line. A target line of 0 places the lines at the beginning of the file.

  Set to the first of the moved lines.
None.

mk[exrc][!] file
    Write the abbreviations, editor options and maps to the specified file. Information is written in a form which can later be read back in using the command. If already exists, the command will fail. This check can be overridden by appending a character to the command.

  Unchanged.
None.

n[ext][!] [file ...]
    Edit the next file from the argument list. The command will fail if the file has been modified since the last complete write. This check can be overridden by appending the character to the command name. The argument list can optionally be replaced by specifying a new one as arguments to this command. In this case, editing starts with the first file on the new list.

    Capitalizing the first letter of the command, i.e. while in mode, will set the argument list and edit the file in a new screen. In this case, any modifications to the current file are ignored.

  Set as described for the
command. Affected by the options [autowrite] and [writeany .]

[line] o[pen] /pattern/ [flags]
    Enter open mode. Open mode is the same as being in but with a one-line window. All the standard commands are available. If a match is found for the optional RE argument, the cursor is set to the start of the matching pattern.

  Unchanged, unless the optional RE is specified, in which case it is
set to the line where the matching pattern is found. Affected by the [open] option.

pre[serve]
    Save the file in a form that can later be recovered using the option. When the file is preserved, an email message is sent to the user.

  Unchanged.
None.

prev[ious][!]
    Edit the previous file from the argument list. The command will fail if the file has been modified since the last complete write. This check can be overridden by appending the character to the command name.

    Capitalizing the first letter of the command, i.e. while in mode, will edit the file in a new screen. In this case, any modifications to the current file are ignored.

  Set as described for the
command. Affected by the options [autowrite] and [writeany .] None.

[range] p[rint] [count] [flags]
    Display the specified lines.

  Set to the last line displayed.
Affected by the [list] and [number] option.

[line] pu[t] [buffer]
    Append buffer contents to the current line. If a buffer is specified, its contents are appended to the line, otherwise, the contents of the unnamed buffer are used.

  Set to the line after the current line.
None.

q[uit][!]
    End the editing session. If the file has been modified since the last complete write, the command will fail. This check may be overridden by appending a character to the command.

    If there are more files to edit, the command will fail. Appending a character to the command name or entering two commands (i.e. or in a row) will override this check and the editor will exit.

  Unchanged.
None.

[line] r[ead][!] [file]
    Read a file. A copy of the specified file is appended to the line. If is 0, the copy is inserted at the beginning of the file. If no file is specified, the current file is read; if there is no current file, then becomes the current file. If there is no current file and no is specified, then the command will fail.

    If is preceded by a character, is treated as if it were a shell command, and passed to the program named by the [shell] edit option. The standard and standard error outputs of that command are read into the file after the specified line. The special meaning of the character can be overridden by escaping it with a backslash character.

  When executed from
the current line is set to the last line read. When executed from the current line is set to the first line read. None.

rec[over] file
    Recover if it was previously saved. If no saved file by that name exists, the command behaves equivalently to the command.

  Set as described for the
command. None.

res[ize] [+|-]size
    mode only. Grow or shrink the current screen. If is a positive, signed number, the current screen is grown by that many lines. If is a negative, signed number, the current screen is shrunk by that many lines. If is not signed, the current screen is set to the specified Applicable only to split screens.

  Unchanged.
None.

rew[ind][!]
    Rewind the argument list. If the current file has been modified since the last complete write, the command will fail. This check may be overridden by appending the character to the command.

    Otherwise, the current file is set to the first file in the argument list.

  Set as described for the
command. Affected by the [autowrite] and [writeany] options.

se[t] [option[=[value]] ...] [nooption ...] [option? ...] [all]
    Display or set editor options. When no arguments are specified, the editor option [term ,] and any editor options whose values have been changed from the default settings are displayed. If the argument is specified, the values of all of editor options are displayed.

    Specifying an option name followed by the character causes the current value of that option to be displayed. The can be separated from the option name by whitespace characters. The is necessary only for Boolean valued options. Boolean options can be given values by the form to turn them on, or to turn them off. String and numeric options can be assigned by the form Any whitespace characters in strings can be included literally by preceding each with a backslash. More than one option can be set or listed by a single set command, by specifying multiple arguments, each separated from the next by whitespace characters.

  Unchanged.
None.

sh[ell]
    Run the shell program. The program named by the [shell] option is run with a (for interactive) flag. Editing is resumed when that program exits.

  Unchanged.
Affected by the [shell] option.

so[urce] file
    Read and execute commands from a file. commands may be nested.

  Unchanged.
None.

[range] s[ubstitute] [/pattern/replace/] [options] [count] [flags]

[range] & [options] [count] [flags]

[range] ~ [options] [count] [flags]
    Make substitutions. Replace the first instance of with the string on the specified line(s). If the argument is not specified, the from the previous command is used. Any character other than an alphabetic, numeric, <blank> or backslash character may be used as the delimiter.

    If includes the letter (confirm), you will be prompted for confirmation before each replacement is done. An affirmative response (in English, a character) causes the replacement to be made. A quit response (in English, a character) causes the command to be terminated. Any other response causes the replacement not to be made, and the command continues. If includes the letter (global), all nonoverlapping instances of in the line are replaced.

    The version of the command is the same as not specifying a pattern or replacement string to the command, and the is replaced by the pattern and replacement information from the previous substitute command.

    The version of the command is the same as and except that the search pattern used is the last RE used in command, not necessarily the one used in the last command.

    For example, in the sequence s/red/blue/ /green ~ the is equivalent to

    The command may be interrupted, using the terminal interrupt character. All substitutions completed before the interrupt are retained.

  Set to the last line upon which a substitution was made.
Affected by the [ignorecase] and [magic] option.

su[spend][!]

st[op][!]

<control-Z>
    Suspend the edit session. Appending a character to these commands turns off the [autowrite] option for the command.

  Unchanged.
Affected by the [autowrite] and [writeany] options.

ta[g][!] tagstring
    Edit the file containing the specified tag. If the tag is in a different file, then the new file is edited. If the current file has been modified since the last complete write, the command will fail. This check can be overridden by appending the character to the command name.

    The command searches for in the tags file(s) specified by the option. (See for more information on tags files.)

    Capitalizing the first letter of the command, i.e. while in mode, will edit the file in a new screen. In this case, any modifications to the current file are ignored.

  Set to the line indicated by the tag.
Affected by the [autowrite ,] [taglength ,] [tags] and [writeany] options.

tagn[ext][!]
    Edit the file containing the next context for the current tag. If the context is in a different file, then the new file is edited. If the current file has been modified since the last complete write, the command will fail. This check can be overridden by appending the character to the command name.

    Capitalizing the first letter of the command, i.e. while in mode, will edit the file in a new screen. In this case, any modifications to the current file are ignored.

  Set to the line indicated by the tag.
Affected by the [autowrite] and [writeany] options.

tagp[op][!] [file | number]
    Pop to the specified tag in the tags stack. If neither or is specified, the command pops to the most recent entry on the tags stack. If or is specified, the command pops to the most recent entry in the tags stack for that file, or numbered entry in the tags stack, respectively. (See the command for information on displaying the tags stack.)

    If the file has been modified since the last complete write, the command will fail. This check may be overridden by appending a character to the command name.

  Set to the line indicated by the tag.
Affected by the [autowrite] and [writeany] options.

tagpr[ev][!]
    Edit the file containing the previous context for the current tag. If the context is in a different file, then the new file is edited. If the current file has been modified since the last complete write, the command will fail. This check can be overridden by appending the character to the command name.

    Capitalizing the first letter of the command, i.e. while in mode, will edit the file in a new screen. In this case, any modifications to the current file are ignored.

  Set to the line indicated by the tag.
Affected by the [autowrite] and [writeany] options.

tagt[op][!]
    Pop to the least recent tag on the tags stack, clearing the tags stack.

    If the file has been modified since the last complete write, the command will fail. This check may be overridden by appending a character to the command name.

  Set to the line indicated by the tag.
Affected by the [autowrite] and [writeany] options.

una[bbrev] lhs
    Delete an abbreviation. Delete from the current list of abbreviations.

  Unchanged.
None.

u[ndo]
    Undo the last change made to the file. Changes made by and map sequences are considered a single command. If repeated, the command alternates between these two states, and is its own inverse.

  Set to the last line modified by the command.
None.

unm[ap][!] lhs
    Unmap a mapped string. Delete the command mode map definition for If a character is appended to the command name, delete the text input mode map definition instead.

  Unchanged.
None.

ve[rsion]
    Display the version of the editor.

[line] vi[sual] [type] [count] [flags]
    mode only. Enter The is optional, and can be or as in the command, to specify the position of the specified line in the screen window. (The default is to place the line at the top of the screen window.) A specifies the number of lines that will initially be displayed. (The default is the value of the [window] editor option.)

  Unchanged unless
is specified, in which case it is set to that line. None.

vi[sual][!] [+cmd] [file]
    mode only. Edit a new file. Identical to the command.

    Capitalizing the first letter of the command, i.e. will edit the file in a new screen. In this case, any modifications to the current file are ignored.

viu[sage] [command]
    Display usage for a command. If is specified, a usage statement for that command is displayed. Otherwise, usage statements for all commands are displayed.

  Unchanged.
None.

[range] w[rite][!] [>>] [file]

[range] w[rite] [!] [file]

[range] wn[!] [>>] [file]

[range] wq[!] [>>] [file]
    Write the file. The specified lines (the entire file, if no range is given) is written to If is not specified, the current pathname is used. If is specified, and it exists, or if the current pathname was set using the command, and the file already exists, these commands will fail. Appending a character to the command name will override this check and the write will be attempted, regardless.

    Specifying the optional string will cause the write to be appended to the file, in which case no tests are made for the file already existing.

    If the file is preceded by a character, the program named by the shell edit option is invoked with file as its second argument, and the specified lines are passed as standard input to that command. The in this usage must be separated from command name by at least one whitespace character. The special meaning of the may be overridden by escaping it with a backslash character.

    The version of the write command will exit the editor after writing the file, if there are no further files to edit. Appending a character to the command name or entering two commands (i.e. or in a row) will override this check and the editor will exit, ignoring any files that have not yet been edited.

    The version of the write command will move to the next file after writing the file, unless the write fails.

  Unchanged.
Affected by the [readonly] and [writeany] options.

[range] x[it][!] [file]
    Write the file if it has been modified. The specified lines are written to if the file has been modified since the last complete write to any file. If no is specified, the entire file is written.

    The command will exit the editor after writing the file, if there are no further files to edit. Appending a character to the command name or entering two commands (i.e. or in a row) will override this check and the editor will exit, ignoring any files that have not yet been edited.

  Unchanged.
Affected by the [readonly] and [writeany] options.

[range] ya[nk] [buffer] [count]
    Copy the specified lines to a buffer. If no buffer is specified, the unnamed buffer is used.

  Unchanged.
None.

[line] z [type] [count] [flags]
    Adjust the window. If no is specified, then lines following the specified line are displayed. The default is the value of the [window] option. The argument changes the position at which is displayed on the screen by changing the number of lines displayed before and after The following characters may be used:

  Place the line at the bottom of the screen.
Place the line at the top of the screen. Place the line in the middle of the screen. Write out count lines starting lines before the net effect of this is that a command following a command writes the previous page. Center on the screen with a line of hyphens displayed immediately before and after it. The number of preceding and following lines of text displayed are reduced to account for those lines.

  Set to the last line displayed, with the exception of the
where the current line is set to the line specified by the command. Affected by the [scroll] option.