vi

display-oriented interactive text editor

Command


SYNOPSIS

vi [-elRsvx] [-c command] [-t tag] [-w size] [file ...]

vi [-elRsvx] [+command] [-t tag] [-w size] [file ...]


CONVENTIONS

Throughout this document the following symbols are used:
CTRL-L

CTRL followed by a single letter indicates the control character transmitted by holding down the CTRL key and the letter key at the same time.

BACKSPACE

This indicates the real backspace key. On the PC, this has a back-arrow (->) on it. This may differ from the CTRL-H key.

ENTER

This indicates the ENTER key, which is labelled RETURN on some keyboards. This may differ in effect from the CTRL-M key.

ESC

This indicates the Escape key.

INTERRUPT

This indicates the break key; CTRL-C or CTRL-BREAK on the PC.

This indicates the right arrow key.

This indicates the left arrow key.

This indicates the down arrow key.

This indicates the up arrow key.


DESCRIPTION

vi is a display-oriented interactive text editor.

There are two components to vi: a screen editor (Vi), and a line editor (Ex). Each has a different set of commands; you can invoke the line editor from within the screen editor and conversely, you can invoke the screen editor from within the line editor.

In the screen editor, you are in either insert mode or command mode. In command mode, every character you type is immediately interpreted as a command. In insert mode, every character you type is added to the text that you are editing.

There are two ways to start your session in Ex mode: you can invoke the command under the name ex; or you can invoke it under the name vi but specify the -e option. Similarly, there are two ways to start your session in Vi mode; you can invoke the command under the name vi (without specifying -e); or you can invoke it under the name ex but specify -v.

Vi and Ex work on text files. If a file contains the NUL character (value 0 or \0), it is turned into the value 0x7F. The newline character is interpreted as a line delimiter. Each line is limited to a maximum length of 1K bytes, including the newline. If any lines exceed that length, they are truncated at that length. If the last line in the file does not end in a newline, a newline is added. In all these abnormal cases, vi marks the file as modified and displays a message.

Options

-c command

runs command before displaying any text on the screen. command is any Ex command. To specify multiple Ex commands, separate them with a vertical line character (|) and enclose them in quotes. The quotes ensure that the shell does not interpret the | as a pipe character. For example,

-c 'set all | ver'
runs both the set all and ver commands prior to displaying text.

-e

invokes ex.

-l

sets lisp mode. The ( and ) commands use blocks of lisp code as their context rather than sentences.

-R

sets the readonly variable, preventing the accidental overwriting of files. Any command that writes to a file requires the ! suffix.

-s

turns on quiet mode; this tells the editor not to display file information messages, thus allowing Ex to be used as a filter; since it doesn't display the file, it doesn't read the value of the TERM environment variable. This option also keeps Ex from reading any startup files (ex.rc or the file specified by EXINIT).

-t tag

edits the file containing the specified tag and sets the virtual position in the edit buffer to point of definition for the tag. (See ctags.) This is the same as the Ex tag command (described later).

-v

puts the editor into Vi mode. With vi, its use is redundant.

-x

prompts you for an encryption key. All files read and written are run through the crypt utility using the key that you enter. The crypt utility must be in the current search path.

-w size

sets the option variable window to size. See section Set Option Variables for more information.

+ command

is an obsolete version of the -c option.

Current Position Pointer

The current position pointer indicates a position in the text that is currently being edited (or has just been edited). In Ex mode, the current position pointer is just the line number of the line being edited. In Vi mode, the pointer gives this line number plus the position of the cursor within the line. The line indicated by the current position pointer is always on the screen.

Display Conventions

vi uses three display conventions that should be noted. These lines are not part of the file content and should be ignored.

Vi Command Summary

Vi commands may be divided into several categories.
(a)
Scrolling commands

adjust the position of text on the screen. The current position pointer only changes if the current line is scrolled off the screen. For example, CTRL-E scrolls the text on the screen up one line. The cursor remains pointing to the same text that it was pointing to, unless that text is moved off the screen.

(b)
Movement commands

move the cursor in the file. For example, the character j moves the cursor down one line and the screen is scrolled only if necessary. There are two types of movement commands: absolute movements and context-dependent movements. An absolute movement moves the cursor, regardless of the nature of the surrounding text; for example, j always moves the cursor down one line. A context-dependent movement moves the cursor based on the nature of the text; for example, w moves the cursor to the beginning of the next word, so it must look at the text to determine where the next word begins.

(c)
Manipulation

commands let you change the text that is already in the file.

(d)
Text insertion

commands let you add new text to the existing text.

Vi scrolling and movement commands may be preceded by a decimal integer which serves as a count, as in:
[count] command
count means different things with different commands. If you type count, it is not displayed anywhere on the screen.

Scrolling

CTRL-B

scrolls text back a page (that is, a screen), less two lines. The cursor is placed on the bottom line of the screen. count specifies a number of pages to scroll. The default value for count is 1.

CTRL-D

scrolls text onto the bottom of the screen. The current position pointer moves forward the same amount in the text, which means that the cursor stays in the same relative position on the screen. If count is given, the screen scrolls forward by the given number of lines; this number is used for all future CTRL-D and CTRL-U commands (until a new count is given). The default scrolling amount is half the screen.

CTRL-E

scrolls a new line onto the bottom of the screen. The current position pointer is not changed unless the current line scrolls off the top of the screen; then the pointer is set to the top line. If count is given, the screen scrolls forward the given number of lines. The default value for count is 1.

CTRL-F

scrolls text forward a page (that is, a screen), less two lines. The cursor is placed on the top line of the screen. count specifies the number of pages to scroll. The default value for count is 1.

CTRL-U

scrolls text onto the top of the screen. The current position pointer moves backward the same amount in the text, which means that the cursor stays in the same relative position on the screen. count operates as for CTRL-D. The default scrolling amount is half the screen.

CTRL-Y

scrolls a new line onto the top of the screen. The current position pointer is not changed unless the current line scrolls off the bottom of the screen; then the pointer is set to the bottom line. If count is given, the screen scrolls backward the given number of lines. The default value for count is 1.

[n] z [m] type

redraws the screen in a window of m lines. type determines the position of the current line. If type is the newline character, the current line is placed at the top of the window. If type is a period (.), the current line is placed in the middle of the window. If type is a minus sign (-), the current line is placed at the bottom of the window. If n is given, the current position pointer is first set to that absolute line number; then the screen is positioned according to type. If you omit n, it defaults to the current line. If you omit m, it defaults to window (see Set Option Variables).

Absolute Movement

All the following movement commands except m, 0, ^, `, and ' may be preceded by count to repeat the movement that many times.
G

moves to the absolute line number specified as count. If count is zero or is not specified, the cursor is moved to the last line of the file.

h
CTRL-H
BACKSPACE

moves the cursor one position to the left.

j
CTRL-J
CTRL-N

moves the cursor to the next line at the same column on the screen. Scroll the screen one line if needed.

k
CTRL-P

moves the cursor to the previous line at the same column on the screen. Scroll the screen up one line if needed.

l
SPACE

moves the cursor one position to the right.

m

records the current position pointer under a mark name. A mark name is a single lowercase letter, given immediately after the m. For example, the command ma records the current location of the current position pointer under the name a.

0

(Zero) moves the cursor to the first character of the current line.

+
CTRL-M

moves the cursor to the first non-blank character on the next line. The screen scrolls one line if needed.

-

moves the cursor to the first non-space character on the previous line. The screen scrolls one line if needed.

|

moves the cursor to the column number specified as count. This is a screen column number, not a line offset. If count is greater than the length of the current line, vi moves the cursor to the last character on the line. If the column indicated is spanned by a tab, vi moves the cursor to the first character after the tab.

^

moves the cursor to the first non-blank character of the current line.

_

moves the cursor to the first non-blank character of a line. count specifies the number of lines, including the current line, to move forward. As a result, the command 1_ is the same as ^.

$

moves the cursor forward to the end of a line. count specifies the number of lines, including the current line, to move forward.

`

when followed by a mark name, moves the cursor to the position that has been associated with that name. The position is set by the m command. A grave character followed by another grave character moves the cursor to the previous context. The previous context is typically the last place where you made a change. More precisely, the previous context is set whenever you move the cursor in a non-relative manner.

'

is similar to the grave (`) character, except that the cursor is set to the first non-blank character on the marked line.

Movement By Context

vi defines a word in the following two ways: vi defines a full word as a sequence of non-blank characters delimited at both ends by blank characters (SPACE, TAB, NEWLINE) or by the beginning or end of a line or file.
B

moves the cursor back to the first character of the current full word. If the cursor is already at the beginning of a full word, vi moves it to the first character of the preceding full word.

b

moves the cursor back to the first character of the current word. If the cursor is already at the beginning of a word, vi moves it to the first character of the preceding word.

E

moves the cursor forward to the end of the current full word. If the cursor is already at the end of a full word, vi moves it to the last character of the next full word.

e

moves the cursor forward to the end of the current word. If the cursor is already at the end of a word, vi moves it to the last character of the next word.

Fc

searches backward in the line for the single character c and positions the cursor on top of it. When count is given, the editor searches back for the countth such character.

fc

searches forward in the line for the single character c and positions the cursor on top of it. When count is given, the editor searches for the countth such character.

H

places the cursor on the first non-blank character of the top line of the screen. count specifies the number of lines from the top of the screen.

L

places the cursor on the first non-blank character of the bottom line of the screen. count specifies the number of lines up from the bottom of the screen.

M

places the cursor on the first non-blank character of the middle line of the screen.

N

repeats previous / or ? command, but in the opposite direction.

n

repeats previous / or ? command.

Tc

searches backward in the line for the character c and positions the cursor after the character being sought. count searches backward for the countth matching character and then positions the cursor after the character being sought.

tc

searches forward in the line for the character c and positions the cursor on the preceding character. count searches forward for the countth matching character and positions the cursor on the preceding character.

W

moves to the start of the next full word.

w

moves to the start of the next word.

(

moves back to the beginning of the current sentence. A sentence is bounded by a period (.), exclamation mark (!), or question mark (?); followed by any number of closing double quotes, ("), closing single quotes ('), closing parentheses (), or closing square brackets (]); followed by two spaces or the end of the line. Paragraph and section boundaries are also sentence boundaries; see [[ and {.

)

moves to the beginning of the next sentence. See ( for the definition of a sentence.

{

moves back to the beginning of a paragraph. A paragraph begins on a blank line, a section boundary (see [[) or a text formatter macro in the paragraphs variable.

}

moves to the beginning of the next paragraph. See { for the definition of a paragraph.

[[

moves back to the beginning of a section. A section begins on lines starting with a formfeed (CTRL-L); starting with an open brace {; a text formatter macro in the sections variable; or begin or end of file.

]]

moves to the beginning of the next section. See [[ for the definition of a section.

%

finds the balancing character to that under the cursor. The character should be one of the following characters:

[{(<  >)}].
;

repeats the previous F, f, T, or t command.

,

repeats the previous F, f, T, or t command in the opposite direction.

/regexp

searches forward in the file for a line matching the regular expression regexp and positions the cursor at the first character of the matching string. When used with an operator to define a text range, the range begins with the character at the current cursor position and ends with the first character of the matching string. You can specify whole lines by following regexp with /+n or /-n where n is the offset from the matched line.

?regexp

is similar to /, but searches backwards in the file.

CTRL-\]

uses the word after the cursor as a tag. See tag under Ex Commands.

Object Manipulators

An object manipulator command works on a block of text. The command character is followed immediately by any kind of movement command. The object that is manipulated by the object manipulator command is the text from the current position pointer to wherever the movement command would leave the cursor.

For example, in dL, d is the object manipulator command to delete an object. It is followed by the movement command L which means move to the bottom line of the screen. The object manipulated by the command thus extends from the current line to the bottom line on the screen; these lines are deleted.

Normally an object extends up to, but not including, the position of the cursor after the move command; however, some movements work in a line mode; for example, L puts the cursor on the first non-blank character of the last line on the screen. If it is used in an object manipulation command, it includes the entire starting line and the entire ending line. Some other objects include the cursor position; for example, d$ deletes up to and including the last character on a line; by itself the $ would have placed the cursor on the final character. Repeating the command letter (or symbol) implies working on a line basis; thus 5dd deletes five lines.

Objects that are deleted or otherwise manipulated have their original values placed in a buffer, an area of computer memory that can hold text. There are several ways this can be done:
  1. You can use a named buffer. Buffers are named with single lowercase letters. To place an object in a buffer, type a double quote " followed by the buffer name, followed by the object manipulator command, as in
    "adL
    
    This deletes text from the current line to the bottom line on the screen and puts the deleted text in buffer a. Normally, this sort of operation overwrites the current contents of the buffer; however, if you use the same form but specify the buffer name in uppercase, the object is appended to the current contents of the buffer. For example,
    "AdL
    
    deletes from the current line to the bottom line on the screen, and adds the deleted text to buffer a.
  2. If you are deleting material and delete at least one full line, vi uses buffers numbered 1 through 9. The first time a full line or more is deleted, the text is placed in buffer 1. The next time, the old contents of 1 are copied to 2, and the newly deleted text is put into 1. In the same way, deleted text continues to be rippled through the nine numbered buffers. When text is rippled out of buffer 9, it is gone for good.
  3. In all other cases, the object manipulated goes to the unnamed buffer. For example, the unnamed buffer is used if you delete less than a line of text. The unnamed buffer is like the other buffers, but doesn't have a name.
The following examples illustrate the use of buffers.
dL

deletes text from current cursor position through to the bottom of the screen and places it into buffer 1; it also ripples numbered buffers.

ad/fred/

delete from current cursor position through to the next position containing (but not including) the string fred, and place the deleted text into buffer a.

dw

deletes the current word and places it in an unnamed buffer.

The object manipulator commands are:
c

deletes the object and enters insert mode for text insertion after the current cursor position. If less than one line is changed, a dollar sign ($) is placed on the final character of the object and typing goes directly over top of the current object until the dollar sign ($) is reached. Additional text is inserted, and the existing text shifts to make room for the new text.

d

deletes the object.

y

yanks the object to the appropriate buffer; the original object is not changed. This may be used to duplicate or copy objects.

<

shifts the object left by the value of the variable shiftwidth. This operator always works on a line basis. This command replaces existing blanks and tabs at the beginning of the line with the minimum number of tabs and spaces required to create the new indent amount. count shifts count lines.

>

shifts the object right by the value of the variable shiftwidth. This operator always works on a line basis. This command replaces existing blanks and tabs at the beginning of the line with the minimum number of tabs and spaces required to create the new indent amount. count shifts count lines.

!

filters the object through an external command. After typing the object, the command line opens up for a system command which is parsed in the same manner as the Ex system command (:!). This operator then invokes the given command and sends the entire object on a line basis to that command. The object is then deleted and the output from the command replaces it. For example, 1G!Gsort moves to the first line of the file; then takes all the text from the first line to the last line and runs it through the sort command.

Object Manipulator Abbreviations

To make things easier, vi supports the following shorthand commands. Each can be preceded by count and/or by a buffer name to save the manipulated text.
C

changes to the end of the current line. This is equivalent to the c$ command.

D

deletes to the end of the current line. This is equivalent to the d$ command.

S

substitutes current line. This is equivalent to the cc command.

s

substitutes current character. This is equivalent to the cl command.

X

deletes the previous character. This is equivalent to the dh command.

x

deletes the current character. This is equivalent to the dl command.

Y

yanks current line. This is equivalent to the yy command.

Inserting Text

vi supports the following commands for inserting text:
A

enters insert mode at end of line. This is equivalent to the $a command.

a

enters insert mode after the current cursor position.

I

enters insert mode before first non-blank character on line. This is equivalent to the ^i command.

i

enters insert mode before the current cursor position.

O

opens up a new line before the current line and enters insert mode on it.

o

opens up a new line after the current line and enters insert mode on it.

R

replaces characters on the screen with characters typed up to the next ESC. Each character typed overlays a character on the screen. The newline character is an exception; it is simply inserted and no other character is replaced. While you are doing this, the screen may not correspond exactly to the contents of the file, due to tabs, etc. The screen is properly updated when you leave insert mode.

r

replaces the character under the cursor with the next character typed. When count is given, count characters following the cursor are all changed to the next character typed. If count is given and the newline character is the replacement character, count characters are deleted (as usual) and replaced with a single newline character, not count newlines.

Miscellaneous

J

joins count lines together. If you do not specify count or count is less than 2, vi uses a count of 2, joining the current line and the next line. This command supplies appropriate spacing: one space between words, two spaces after a period, and no spaces at all when the first character of the next line is a closing parenthesis ()). When a line ends with white space, vi retains the white space, does not add any further spaces, and then appends the next line.

P

puts buffer contents before the cursor. This is also called a paste operation. If preceded by quote buffername (for example, "b), the contents of that buffer are used; otherwise the contents of the unnamed buffer are used. If the buffer was created in Ex mode, the contents of the buffer are inserted before the current line. If the buffer was created in Vi mode, the contents are inserted before the cursor. As a special case, if a paste operation is repeated with the period (.) command and it used a numbered buffer, the number of the buffer is incremented. Thus, "1p....., pastes in the contents of buffer 1 through buffer 6; in other words the last six things that were deleted are put back.

p

is similar to P except that text is pasted after the cursor instead of before it.

Q

switches to Ex mode. You leave Vi mode and the Ex prompt is shown on the bottom line of the screen.

U

undoes all changes to current line. As soon as you move off a line or invoke an Ex command on the line, the original contents of the line are forgotten and U is not successful.

u

undoes last change. If repeated, you undo the undo (that is, go back to what the text was before the undo). Some operations are treated as single changes; for example, everything done by a global G is undone with undo.

ZZ

writes the file out, if changed, then exits. Equivalent to the Ex command xit.

.

repeats the last command. Any command which changes the contents of the file may be repeated by this command. If you do not specify count with the . command, vi uses the count that was specified for the command being repeated.

~

toggles the case of the character under the cursor and moves the cursor right by one. This command may be preceded by count to change the case of count characters.

&

repeats the previous Ex substitute command using the current line as the target. Flags set by the previous command are ignored. Equivalent to the Ex command &.

:

invokes an Ex command. The editor places the cursor on the bottom line of the screen and displays a colon (:) to prompt for input. You may then type an Ex command; when you press ESC or ENTER, the line you have entered is passed to Ex and run there.

@

invokes a macro. When the next character is a letter from a through z, vi treats it as the name of a buffer. The contents of that buffer are treated as input typed to vi. The text of a macro may contain an @ calling another macro. A macro may call itself, provided it is invoked at the end of the macro (tail recursion). Such a macro runs forever or until an error occurs or the INTERRUPT key is pressed. A macro that invokes itself at the beginning (head recursion) loops until it runs out of memory. A vi error terminates all currently executing macros. All changes made during a macro call are treated as a unit and may be undone with a single u command.

CTRL-G

displays the current path name, current line number, total number of lines in the file, and the percentage of the way through the file. This is equivalent to invoking the Ex command file.

CTRL-L

redraws the screen assuming another process has written on it. This should normally never happen unless a filter ! command writes to the screen rather than the standard output.

CTRL-R

redraws the screen, removing any deleted lines flagged with the @ convention.

CTRL-^

switches to editing the alternate file (see write under Ex Commands). If you attempt this and you have not written out the file since you made the most recent change, vi does not switch to the alternate file.

Special Keys

Keys like the function keys and the cursor arrow keys do not correspond to particular characters. These keys can be programmed to be interpreted as any character sequence, using the Ex map and map! commands. See vipc for the symbolic names and default programming of these keys.

Insert Mode

The object manipulation command c, and the text insertion commands [AaIiOoRr] put Vi into INSERT mode. In this mode, most characters typed are inserted in the file. The following characters have special meaning.
CTRL-D

decrements the autoindent for the current line by one level. This is only relevant if the variable autoindent is on. See the Set Option Variables section for more details.

CTRL-H
BACKSPACE

deletes the last typed character. The character is not removed from the screen; however it is no longer in your file. When you backspace over characters, new text overwrites the old ones. You are permitted to backspace to the start of the current line regardless of where you started to insert text. (This is not true of some other versions of Vi.)

CTRL-J
CTRL-M
ENTER

ends the current line and starts a new one.

CTRL-Q
CTRL-V

inserts the next character typed as that character instead of using its special meaning. This is normally used to escape, say, the ESC character itself. It is impossible to escape CTRL-J or the null character in your line.

CTRL-T

increments the autoindent for the current line by one level. This is only relevant if the variable autoindent is on.

CTRL-W

deletes the word preceding the cursor and blanks. Even though the characters are not removed from the screen, they are no longer in your file.

CTRL-@

when this is the first character typed after entering insert mode, the previously typed insert mode contents are repeated; after this, you exit insert mode. Only up to the first 256 characters from the previous insertion are inserted. CTRL-@ is the keystroke that performs this operation on UNIX;

backs over the last typed character. Characters typed are inserted before these characters backed over.

CTRL-U

deletes inserted line. The cursor is moved to the first character that was inserted on the current line. The characters are not removed from the screen; however they are no longer in your file. If you have backspaced past the point that you started inserting text, this deletes to the start of the current line. You can change the character that deletes an inserted line with the linedelete variable described in Set Option Variables.

ESC
INTERRUPT

leaves insert mode.

Ex Command Mode

vi enters Ex command mode if the program is invoked with the -e option or if the Q command is issued from Vi. You can issue a single Ex command from Vi mode by using the : command.

An Ex command takes the general form
[address-list] [[command] [!] [parameters]]
Each part is optional and may be invalid for some commands. You may specify multiple commands on a line by separating them with a vertical line character (|).
address-list

Commands may take zero, one, or two addresses. The address % is a short form to indicate the entire file. You may omit any or all of the addresses. In the command description in the Ex Commands section, the addresses shown are the addresses that the commands use by default.

Possible default addresses are:

[.,.]

Indicates a two address line range defaulting to the current line.

[1,$]

Indicates a two address line range defaulting to the entire file.

[.+1]

Indicates a single address defaulting to the next line.

address

An address refers to a line in the text being edited. An address may be an expression involving the following forms:

.

The value of the current line indicator.

n

A line number indicating an absolute line in the file; the first line has absolute line number 1.

$

The last line in the file.

+[n]

n lines forward in the file. If you omit n, it defaults to 1.

-[n]

n lines backward in the file. If you omit n, it defaults to 1.

'x

The value of the mark x.

/pat/

Search for regular expression pat forward from the current line.

?pat?

Search for regular expression pat backwards from the current line.

Thus,
/pattern/+3
++
100
are three addresses: the first searches for a pattern and then goes three lines further; the second indicates two lines after the current line; and the third indicates the 100th line in the file.

command

The command is a word, which can be abbreviated. Characters shown in square brackets are optional. For example,

a[ppend]
indicates that the append command can be abbreviated to simply a.

!

Some commands have a variant; this is usually toggled with an exclamation mark (!) immediately after the command.

parameters

Many Ex commands use parameters to allow you to specify more information about the command. Common parameters include:

buffer

specifies one of the named areas for saving text. For more information, see the description of buffers in the Object Manipulators section of this reference page.

count

is a positive integer, specifying the number of lines to be affected by the command. If you omit count, it defaults to 1.

file

is the path name for a file. If file includes the % character, vi replaces that character with the path name of the current file. If file includes the # character, vi replaces that character with the path name of the alternate file. If you do not specify file, the default is the current file.

flags

indicate actions to be taken after the command is run. It may consist of leading plus (+) and minus (-) signs to adjust the value of the current line indicator; followed by p, l, or # to display, list or number a line.

Thus
.+5 delete 6 ++#
deletes starting five lines down from the current line; six lines are deleted; the current line indicator is set to the following line, then incremented by two; and that line is displayed with its line number.

Regular Expressions and Replacements

Many Ex commands use regular expressions when searching and replacing text. A regular expression (indicated by pat in the command descriptions) is used to match a set of characters. A replacement (indicated by repl in the command descriptions) describes what to put back in a line for the set of characters matched by the regular expression.

A regular expression consists of a string of normal characters which exactly match characters in a line. These may be intermixed with special characters (known as metacharacters) which allow matching in some special manner. Metacharacters may themselves be matched directly by preceding them with the backslash (\) character. If the variable magic (see the Set Option Variables section) is turned off, all but two of the metacharacters are disabled; in this case, the backslash character must precede them to allow their use as metacharacters. See regexp for examples.

Regular Expression Summary

^

matches the start of a line. This is only a metacharacter if it is the first character in the expression.

$

matches the end of a line. This is only a metacharacter if it is the last character in the expression.

.

matches any single character.

*

Matches zero or more occurrences of the previous expression.

\<

matches the empty string preceding the start of a word. A word is a series of alphanumeric or underscore characters preceded and followed by characters which are not alphanumeric or underscore.

\>

matches the empty string following the end of a word. A word is a series of alphanumeric or underscore characters preceded and followed by characters which are not alphanumeric or underscore.

[string]

matches any of the characters in the class of characters defined by string. For example, [aeiouy] matches any of the vowels. You can put a range of characters in a class by specifying the first and last characters of the range, with a hyphen (-) between them. For example, in ASCII [A-Za-z] matches any upper or lowercase letter. If the first character of a class is the caret (^), the class matches any character not specified inside the square brackets. Thus, in ASCII [a-z_][^0-9] matches a single alphabetic character or the underscore, followed by any non-numeric character.

\(...\)

(escaped parentheses) may surround a set of characters in the pattern. See the discussion of the \n replacement pattern, that appears under Replacement Pattern Summary, to find the meaning of this construct. This is not affected by the setting of the variable magic (see the Set Option Variables section).

~

matches the replacement part of the last substitute command.

Replacement Pattern Summary

&

is replaced by the entire string of matched characters.

~

is replaced by the entire replacement pattern from the last substitute.

\n

is replaced by the string that matched the nth occurrence of a \( ... \) in the regular expression. For example, consider

s/\([a-zA-Z]*\)our/\1or/
The \1 represents the string that matched the regular expression \([a-zA-Z]*\). Thus the previous command might change the word colour to color.

\u

turns the next character in the replacement to uppercase.

\l

turns the next character in the replacement to lowercase.

\U

turns subsequent characters in the replacement to uppercase.

\L

turns subsequent characters in the replacement to lowercase.

\E, \e

turns off the effects of \U or \L.

Ex Commands

These commands can be entered as shown in Ex mode. In Vi mode, they must be preceded by the colon (:) character.
ab[breviate] [word rhs]

indicates the word word is to be interpreted as an abbreviation for rhs (see previous definition of word in the section entitled Movement By Context). If you enter word surrounded by white space (or any characters that cannot be part of a word) in Vi INSERT mode, it is automatically changed into rhs. If you do not specify any arguments for the ab command, it displays the abbreviations that are already defined. Abbreviated names cannot contain # or any other forms of punctuation.

[.] a[ppend][!]

enters Ex INSERT mode. Text is read and placed after the specified line. An input line consisting of one period (.) leaves INSERT mode without inserting the period. If you specify an address of zero, text is inserted before the first line of the file. The current line indicator points to the last line typed.

If an exclamation mark (!) is specified, the autoindent option is toggled during input. This command may not be invoked from Vi mode.

ar[gs]

displays the current list of files being edited. The current file is shown enclosed by square brackets.

cd[!] [path]

changes the current directory to path. If you omit path, cd sets the current working directory to the directory identified by the home variable. If path is a relative path name, cd searches for it using the directories specified in the cdpath variable. If path is - (the dash), then cd changes to the previous working directory. If you have modified the buffer since the last write, vi displays a warning message. You can override this behavior by including the exclamation mark (!).

[.,.] c[hange][!] [count]

deletes the line range given and then enters INSERT mode. If an exclamation mark (!) is specified, autoindent is toggled during input. This command may not be invoked from Vi mode.

chd[ir][!] [path]

is the same as cd.

[.,.] co[py] addr [flags]

copies the line range given after addr. If addr is zero, the lines are inserted before the first line of the file. The current line indicator points to the last line of the inserted copied text.

[.,.] d[elete] [buffer] [count] [flags]

deletes the specified line range. After deleting the line range, the current line indicator points to the line after the deleted range. A buffer may be specified as a letter a-z; if so, deleted lines are saved in the buffer with that name. If an uppercase letter is specified for buffer, the lines are appended to the buffer of the corresponding lowercase name. If no buffer name is given, deleted lines go to the unnamed buffer.

e[dit] [!] [+line] [file]
ex [!] [+line] [file]

begins a new editing session on a new file; the new file replaces the old file on the screen. Normally, this command is invalid if you have modified the contents of the current file without writing it back to the file. Specifying an exclamation mark (!) goes on to start a new session even if you have not saved the changes of the current session. You can specify line as either a line number or as a string of the form /regexp or ?regexp where regexp is a regular expression. When line is a line number, the current line indicator is set to that position. When it has the form /regexp, vi searches forward through the file for the first occurrence of regexp and sets the current line indicator to that line. ?regexp is similar to /regexp, except that vi searches through the file backwards. If you omit line and do not specify a file, the value of the current line indicator does not change; otherwise if a file is specified, the current line indicator is set to either the first or last line of tha buffer, depending upon whether the command was issued in Vi or Ex mode.

The edit command does not destroy buffers, so you can use the yank and put commands to move text between files. The edit command sets the alternate file name to the old file, so you can return to that file with e #.

f[ile] [file]

changes the current file name to file and marks it [Not Edited]. If this file exists, it may not be overwritten without using the exclamation mark (!) variant of the write command. If no file is specified, the editor displays information about the current file.

[1,$] g[lobal] [!] /pat/ [commands]

matches pat against every line in the given range. On lines which match, the commands are run. If the exclamation mark (!) variant is set, the commands are run on lines which do not match. This is the same as using the v command (described later in this section).

The global command and the undo command may not occur in the list of commands. A subsequent undo command undoes the effect of the entire global command. In Ex mode, multiple command lines may be entered by ending all but the last with backslash (\). Commands which would take input are permitted; the input is included in the command list, and the trailing period (.) may be omitted at the end of the list. For example,
g/rhino/a\
hippo
appends the single line hippo to each line containing rhino. The total length of a global command list is limited (see LIMITS).

You can use any non-alphabetic character to delimit pat instead of the slash (/).

[.] i[nsert][!]

enters Ex INSERT mode, reads text and places it before the specified line; otherwise, this is identical to the append command. This command may not be entered from Vi mode.

[.,.+1] j[oin][!] [count] [flags]

joins together the lines of text within the range. If an exclamation mark (!) is specified, the lines are join with no content change.

If an exclamation mark (!) is not specified, all white space between adjacent joined lines is deleted and replaced with zero, one, or two spaces. Two spaces are used if the previous line ended in a period (.); zero spaces if the joined line begins with a closing parenthesis ()); and one space in all other cases.

[.] k x

is synonymous with the mark command.

[.,.] l[ist] [count] [flags]

displays the line range in a visually unambiguous manner. This command displays tabs as ^I, and the end of lines as $. The only useful flag is #, for line numbering. The current line indicator points to the last line displayed.

map[!] [lhs rhs]

defines macros for use in Vi. The lhs is a string of characters; whenever that string is typed exactly, vi behaves as if the string rhs had been typed. If lhs is more than one character long, none of the characters are echoed or acted upon until either a character is typed that isn't in the lhs (in which case all the characters up to that point in the lhs are run) or the last character of lhs is typed. If the variable remap is set, rhs itself may contain macros. If the flag ! is specified, the map applies within Vi INSERT mode; otherwise it applies to command mode. A map command with no arguments lists all macros currently defined. Special keys, such as function keys, may also be set; see vipc.

[.] ma[rk] x

records the specified line as being marked with the single lowercase letter x. The line may then be addressed at any point as 'x.

[.,.] m[ove] addr [flags]

moves the specified line range after the addr given. If addr is zero, the text is moved to the start of the file. The current line indicator is set to the last line moved.

n[ext][!] [+command] [file ...]

begins editing the next file in the file list (where the file list was either specified on the command line or in a previous next command). If the current file has been modified since the last write, Ex normally prevents you from leaving the current file; you can get around this by specifying an exclamation mark (!). If autowrite is set, the current file is written automatically and you go to the next file. If a list of files is specified, they become the new file list. If necessary, expressions in this list are expanded, thus

next *.c
sets the file list to all the files in the current directory with names ending in .c (typically C source files).

[.,.] nu[mber] [count] [flags]
[.,.] # [count] [flags]

displays the specified line range with leading line numbers. The current line indicator points to the last line displayed.

[.] o[pen] [/pat/] [flags]

enters open mode, which is simply Vi mode with a variable length one line window. If a match is found for the regular expression pat in the specified line the cursor is placed at the start of the matching pattern.

You can use any non-alphabetic character to delimit pat instead of the slash (/).

[.,.] p[rint] [count] [flags]

displays the specified line range. The current line indicator points to the last line displayed.

[.] pu[t] [buffer]

pastes deleted or yanked lines back into the file after the given line. If no buffer name is given, the most recently changed buffer is used.

Since the edit command does not destroy buffers, you can use that command in conjunction with put and yank to move text between files.

q[uit][!

exits from Vi/Ex. If the current file has been modified, an exclamation mark (!) must be used or you cannot exit until you write the file.

[.] r[ead][!] [file]

reads the contents of file and inserts them into the current file after the given line number. If the line number is 0, the contents of the given file are inserted at the beginning of the file being edited. If the current file name is not set, a file must be given, and it becomes the current file name; otherwise, if a file is given, it becomes the alternate file name. If the file begins with an exclamation mark (!), it is taken as a system command. The output from that system command is read in via a pipe after the given line number.

rew[ind][!

rewinds the file argument list back to the beginning and starts editing the first file in the list. If the current file has been modified, an exclamation mark (!) must be specified; otherwise, you cannot leave the current file until you have written it out. If autowrite is set, the current file is written out automatically if it needs to be.

se[t] [parameter-list]

assigns or displays the values of option variables. If you do not specify a parameter list, set displays all the variables with values that have changed since the editing session started. If the parameter all is specified, Ex displays all variables and their values. You may use the parameter list to set or display each of many variable values. Each argument in the list is a variable name; if it is a Boolean variable, the value is set on or off depending on whether the name is prefixed by no. Non-Boolean variables alone in an argument are a request to display their values. You may display a Boolean variable's value by appending a question mark (?) to the name. You can set numeric or string variables with

name=value
In a string variable, spaces must be preceded by a backslash. As an example,
set readonly? noautowrite shell=/bin/sh
shows the value of the readonly flag, sets noautowrite, and sets the shell to /bin/sh.
set report report=5
shows the value of the report variable and then sets the value to 5. See section Set Option Variables for further details.

sh[ell]

invokes a subshell. The SHELL environment variable is used to find the name of the shell to run. It can also be one of the shells provided by the MKS Toolkit, such as the MKS KornShell (sh). You normally return to the editor from the launched subshell with the exit.

so[urce] file

runs editor commands from file. A file being run with source may contain source commands of its own.

st[op]

suspends the editor session and returns to system level. For further information, see the description of the Vi command CTRL-Z.

[.,.] s[ubstitute] [/pat/repl/] [options] [count] [flags]

searches each line in the line range for the regular expression pat and replaces matching strings with repl. Normally, Ex only replaces the first matching string in each line; if options contains g (global), all matching strings are changed. If options contains c (confirm), Ex first displays the line with caret (^) characters marking the pat matching location; you can then type y if you want Ex to go ahead with the substitution. pat cannot match over a line boundary; however in Ex mode, repl may contain a newline, escaped by a preceding backslash (\). See the section on regular expressions for full information on both pat and repl. If there is no pat and/or repl, Ex uses the most recently specified regular expression and/or replacement string. You can use any non-alphabetic character in place of the slash (/) to delimit pat and repl.

su[spend]

is the same as stop.

[.,.] t addr [flags]

is the same as the copy command.

ta[g][!] tagname

looks up tagname in the files listed in the variable tags. If the tag name is found in a tags file, that file also contains the name of the file that contains the tag and a regular expression required within that file to locate that tag. If the given file is different from the one you are currently editing, Ex normally begins editing the new file; however, if you have modified the current file since the last time it was written out, Ex does not start editing a new file unless the tag command contains an exclamation mark (!). (If autowrite is on, the current file is automatically written out and the new file read in.) When the new file is read in, the regular expression from the tags file is invoked with the variable magic off (see the Set Option Variables section).

Tag names are typically used to locate C function definitions in C source files. The first step is to create a tags file using the ctags command. Once you do this, you can use the Ex tag command to look up a particular function definition and go directly to that definition in the file that contains it.

All characters in tag names are significant unless the variable taglength is non-zero; in this case, only the given number of characters are used in the comparison.

una[bbreviate] lhs

The abbreviation lhs previously created by abbreviate is deleted.

u[ndo]

undoes the last change or set of changes which modified the buffer. Global changes and Vi macros are considered single changes that can be undone. A second undo undoes the undo restoring the previous state. The edit command may not be undone, since it cleans up the temporary file used to maintain undo information. You cannot undo operating system commands and commands that write output to the file system.

unm[ap][!] lhs

deletes the map of lhs. If the flag !, this applies to the insert mode maps; otherwise it applies to the command mode maps.

[1,$] v /pat/ commands

is the same as the global command with the ! flag; that is, a global for all non-matching lines. You can use any non-alphabetic character to delimit pat instead of the slash (/).

ve[rsion]

displays the current version information for Vi/Ex.

[.] vi[sual] [type] [count] [flags]

enters Vi mode. If no type is specified, the current line is at the top of the screen. If type is caret (^), the bottom line of the screen is one window before the current line. If type is a minus sign, (-), the current line is at the bottom of the screen and if type is a period (.), the current line is in the middle of the screen.

You can use the undo command to undo all changes that occurred during the vi command.

[1,$] w[rite][!] [>>] [file]

writes the given range of lines to file. If two right angle brackets (>>) are included, the lines are appended to the file's current contents. If the current file name is not set, file must be given; this becomes the current file name; otherwise, file (if specified) becomes the alternate file name. If file begins with an exclamation mark (!), it is taken as a system command. vi writes the given range to the command through a pipe.

If a file is given, it must not already exist. The variable readonly must not be set. If a file is not given, the file must be edited; that is, it must be the same file as that read in. All these conditions may be overridden by using the flag !.

[1,$] wn[!] [>>] [file]

is similar to write, except that it begins editing the next file in the file list immediately afterwards (if the write is successful).

[1,$] wq[!] [>>] [file]

is similar to write, except that it exits the editor immediately afterwards (if the write is successful).

[1,$] x[it][!] [file]

if you have modified the current file since the last write, performs a write command using the specified range and file name and terminates.

[.,.] y[ank] [buffer] [count]

copies the given line range to the specified buffer (a letter from a through z). If a buffer is not specified, the unnamed buffer is used.

Since the edit command does not destroy buffers, you can use that command in conjunction with put and yank to move text between files.

[.+1]z [type] [count\] [flags]

displays count lines. If no count is specified, Ex uses the current value of the scroll variable. The lines are displayed with the given line located according to the type. If type is a plus sign (+), the editor displays the given line and a screenful after that. If type is a period (.), the editor displays a screenful with the given line in the middle. If type is a minus sign (-), the editor displays a screenful with the given line at the end. If type is a caret (^), the editor displays the screenful before that and if type is an equals sign (=), the current line is centered on the screen with a line of hyphens displayed immediately before and after it. The current line indicator points to the last line displayed.

[.,.] <[<...] [count] [flags]

shifts the line range by the value of the shiftwidth variable. If there are multiple left angle brackets (<), each one causes another shift. The current line indicator points to the last line of the range. If a count is specified, that many lines are shifted.

[.,.] >[>...] [count] [flags]

shifts the line range right by the value of the shiftwidth variable. If there are multiple right angle brackets (>), each one causes another shift. The current line indicator points to the last line of the range. If a count is specified, that many lines are shifted.

[range] ! command

submits command to be run by the shell named by the shell variable. If a range is given, the command is invoked with the contents of that line range as input. The output from the command then replaces that line range. Thus

1,$!sort
sorts the entire contents of the file.

Substitutions are made in command before it is run. Any occurrences of an exclamation mark (!) are replaced by the previous command line, while occurrences of percentage (%) and hash mark (#) characters are replaced with the path names of the current and alternate files, respectively. If any such substitutions actually take place, the new command line is displayed before it is run. (See read and write under Ex Commands for more information the current and alternate files.)

If the file has been modified and the variable autowrite is on, the file is written before calling the command. If autowrite is off, a warning message is given.

[$] =

displays the given line number. The default line number is the last line of the file. The current line indicator is not changed.

" a line of text

This is a comment.

[.,.] & [options] [count] [flags]

Repeats the last substitute command. If any options, count, or flags are specified, they replace the corresponding items in the previous substitute command.

[.,.] ~ [options] [count] [flags]

repeats the last substitute command; however, the regular expression that is used is the last regular expression; that is, if there has been a search, the search's regular expression is used. The simple substitute with no arguments, or the & command, uses the regular expression from the previous substitute. substitute with an empty regular expression uses the last regular expression, like ~. If any options, count, or flags are specified, they replace the corresponding items in the previous substitute command.

@ buffer

executes each line in buffer as an Ex command. If you do not specify buffer or you specify a buffer named @, the last buffer executed is used.

CTRL-D

displays the number of lines of text given by the scroll variable. The current line indicator points to the last line displayed.

Special Characters in Ex Commands

When an Ex command contains the percentage character (%), the character is replaced by the name of the current file. For example, if you are about to try out a macro and you are worried that the macro may damage the file, you could say
!cp % /tmp
to copy the current file to a safe holding place. As another example, a macro could use the percentage character (%) to refer to the current file.

When an Ex command contains the hash mark (#), the character is replaced by the name of the alternate file. The name of the alternate file may be set with the read command as described previously. Thus a command like
e #
tells Ex to edit the alternate file. Using an alternate file can be particularly convenient when you have two files that you want to edit simultaneously. The command just given lets you flip back and forth between the two files.

Set Option Variables

Option variables are set with the set command. For example,
set autowrite
sets the autowrite option. Options are turned off by putting no in front of the name in the set command, as in
set noautowrite
In the descriptions that follow, the minimal abbreviation of each option variable is shown after the comma.
Note:

There are some non-standard options specific to the PC which are separately documented in vipc.

autoindent, ai

When autoindent is on and you are entering text, the indentation of the current line is used for the new line. In Vi mode, you can change this default indentation by using the control keys CTRL-D (to shift left) and CTRL-T (to shift right). In Ex mode, a tab or spaces may be typed at the start of a line to increase the indent, or a CTRL-D may be typed at the start of the line to remove a level. ^ CTRL-D temporarily removes the indent for the current line. 0 CTRL-D places the current line at a zero indent level, and the next line has this indent level as well.

The size of indent levels is defined by the variable shiftwidth. Based on this value and the value of tabstop, the editor generates the number of tabs and spaces needed to produce the required indent level.

The default is noautoindent.

autoprint, ap

When this option is set in Ex mode, the current line is displayed after the following commands: copy, delete, join, move, put, substitute, undo, &, ~, <, and >. Automatic displaying of lines does not take place inside global commands.

The default is autoprint.

autowrite, aw

When this option is on, the current file is automatically written out if it has been changed since it was last written and you have run any of the following commands: next, rewind, tag, CTRL-^ (Vi), and CTRL-] (Vi). Using an exclamation mark (!) with any of these commands stops the automatic write.

The default is noautowrite.

beautify, bf

When this option is on, the editor discards all non-printing characters from text read in from files.

The default is nobeautify.

cdpath

Used by cd to find relative path names when changing directory. You must delimit entries with a semi-colon (;). If the current directory is to be included in the search, it must be indicated by a dot (.). cdpath defaults to the contents of the CDPATH environment variable if it exists, or to dot (.) if it does not.

directory, dir

The editor uses temporary files with unique names under the given directory. Any error on the temporary files is fatal.

The default is directory=/tmp.

edcompatible

When this option is on, the editor attempts to make substitute commands behave in a way that is compatible with the ed editor. The g and c options on the substitute commands are remembered and toggled by their occurrence. The r option uses the last regular expression rather than the last substitute regular expression. Percentage mark (%) as the entire pattern is equivalent to the previous pattern.

The default is noedcompatible.

errorbells, eb

When this option is on, vi precedes error messages with the alert character. When it is off, the editor warns you of an error by displaying a message using a standout mode of your terminal (such as inverse video).

The default is noerrorbells.

exrc

When this option is on, Ex and Vi access any ex.rc (.exrc on UNIX systems) files in the current directory during initialization. If it is off, Ex and Vi ignore such files unless the current directory is the HOME directory.

The default is noexrc.

home

Used as the destination directory by cd. If no path is specified, home defaults to the contents of the HOME environment variable if it exists, or to the vi startup directory if it does not.

ignorecase, ic

When this option is on, the case of letters is ignored when matching strings and regular expressions.

The default is noignorecase.

linedelete

On a UNIX system, Vi sets the line delete character automatically to the current terminal line delete character, as specified by the user. Under DOS or OS/2, ESC is the line delete and is not settable. Under DOS, ESC is valid only in visual mode. Since ESC is used by Vi for other purposes, the linedelete variable sets the line delete character that is used in Vi. The value is the numeric value of the line delete character. The default is 0x15, the ASCII value for CTRL-U. Another popular value is 0x18 for CTRL-X.

list

When this option is on, tabs are displayed as a caret mark (^) rather than being expanded with blanks, and the ends of lines are indicated with a dollar sign ($).

The default is nolist.

magic

When this option is off (nomagic), regular expression characters ^ \ and $ become the only ones with special meanings. All other regular expression metacharacters must be preceded by a backslash (\) to have their special meaning.

The default is magic.

maxbuffers

This is the number of K units (1024 bytes) of memory which is to be used for the editor buffers. These are allocated in units of 16K.

The default is maxbuffers=512, but if that is not available upon entry this is set to the number actually obtained. At least 32K is needed. This is in addition to the code and data space required by vi; this may be as much as 128K. Changing maxbuffers has no effect.

number, nu

When this option is on, line numbers are displayed to the left of the text being edited.

The default is nonumber.

paragraphs

This list of character pairs controls the movement between paragraphs in Vi mode. Lines beginning with a period (.) followed by any pair of characters in the list are paragraph boundaries (for example, .IP). Such lines are typically commands to text formatters like nroff or troff.

The default is paragraphs="IPLPPPQPP LIpplpipbp""

prompt

When this option is on, Ex command mode prompts with a colon (:). (No prompts are given if input is not being read from a terminal.)

The default is prompt.

pwd

This is a read-only variable. The value always refers to the current working directory, and can only be changed by the cd command.

quiet

When this option is on, vi does not display file information messages.

The default is set by the -s option.

readonly

When this option is on, vi does not let you write to the current file.

The default is based on the permissions of the current file. If you do not have write permission on this file, the default is readonly; otherwise the default is set by the -R option.

remap

If this option is on and a map macro is expanded, the expansion is re-examined to see if it too contains map macros.

The default is remap.

report

The editor displays a message whenever you issue a command that affects more than this number of lines.

The default is report=5.

restrict

When this option is on, all file names are restricted to the current directory. No sub-commands may be called. This variable is automatically set if you invoke the editor with a command that starts with the letter r, as in rvi. Once the option is turned on, it cannot be turned off. The default is norestrict.

scroll

This sets the number of lines to scroll for the z (Ex), and CTRL-D (Ex) commands.

The default is the value of the variable window divided by two.

sections

This list of character pairs controls the movement between sections in Vi mode. Lines beginning with a period (.) followed by any pair of characters in the list are section boundaries (for example, .SH). Such lines are typically commands to text formatters like nroff or troff.

The default is sections="SHNHH HU".

shell, sh

This is the name of the shell to be used for ! commands and the shell command.

The default value is taken from the SHELL environment variable.

shiftwidth, sw

This sets the width of indent used by shift commands and autoindent.

The default is shiftwidth=8.

showmatch, sm

If this option is on and you type a closing parenthesis ()) or closing brace (}) in input mode, the cursor moves to the matching open parenthesis or brace. It stays there for about one second and then moves back to where you were. This lets you note the relationship between opening and closing parentheses/braces.

The default is noshowmatch.

showmode

When this option is on, vi displays an indicator in the bottom right-hand corner of the screen if you are in Insert/Open/Change/Replace mode. If no indicator is displayed, you are in Command mode.

The default is noshowmode.

tabstop

Tab stops for screen display in Vi mode are set to multiples of this number.

The default is tabstop=8

taglength, tl

If this variable is non-zero, tags are only compared for this number of characters.

The default is taglength=0.

tags

The value of this variable should be a list of file names separated by a backslash (\) followed by a space. If there is no backslash (\) before the space, vi treats the second and subsequent tags as part of an option = value combination. For example:

set tags=file1\ file2\ file3\
These are used by the tag Ex command and the CTRL-] Vi command. The files are typically created with the ctags program.

The default is tags=tags.

term

The value of this variable is the terminal type.

The TERM environment variable specifies this variable's default value. To specify a setting other than the one specified by the TERM environment variable, you need to set a value for term in the editor initialization file set in the EXINIT environment variable (for more information, see the Editor Initialization section).

For more information on the possible values for TERM, see the envvar reference page.

terse

If this option is on, messages are displayed in a very abbreviated form.

The default is noterse.

visualbell

When this option is on, vi flashes your screen as the visual equivalent of the alert character.

The default is novisualbell.

warn

When this option is on, commands with an exclamation mark (!) display a warning message if the current file has been modified. When off, no message is displayed.

The default is warn.

window

This variable gives the number of text lines available in Vi mode or the default number of lines to display for the z command.

The default is given by the -w option. If it is not specified with the -w option, its value defaults to the environment variable LINES

wrapmargin, wm

If this variable is non-zero in Vi insert mode, when a line reaches this number of characters from the right of the screen, the current word moves down to the next line automatically; you don't have to press ENTER.

The default is wrapmargin=0.

wrapscan, ws

If this option is off, forward searches stop at the end of the file and backward searches stop at the beginning.

The default is wrapscan.

writeany, wa

If this option is off, the editor does not let a file marked [Not edited] overwrite an existing file.

The default is nowriteany.

Editor Initialization

Initialization code consists of one or more Ex commands that are run when the editor starts up. Initialization code may be obtained in several ways.
  1. If there is an environment variable named EXINIT with a non-null value, it is assumed to hold initialization code. vi runs this code using an Ex source command.

  2. If EXINIT does not exist or has a null value, the editor attempts to find a file named ex.rc (.exrc on UNIX systems) under your home directory. If you have an environment variable named HOME, the value of this variable is assumed to be the name of your home directory. vi runs the ex.rc file using an Ex source command. See envvar for more information on these environment variables.

  3. If the EXINIT variable or the $HOME/ex.rc ($HOME/.exrc on UNIX systems) file sets the option variable exrc and there is a file named ex.rc (.exrc on UNIX systems) under the current directory, it is assumed to hold initialization code. vi runs this code using an Ex source command.

  4. vi executes any commands given by the -c or + options.

vi reads the ex.rc file as if it were a sequence of keystrokes typed at the beginning of an Vi session. As a result, the contents of ex.rc must be the same as the characters you would type if you were in Vi. In particular, if the input contains any unusual characters (for example, a carriage return) that you would normally precede with CTRL-V, there must be a CTRL-V in the ex.rc file. When using vi to create ex.rc, you must type CTRL-V CTRL-V to put a CTRL-V character into your initialization file, then CTRL-V followed by the special character. The ex.rc file must show both CTRL-V and the special character.
Note:

If vi does not find a file named ex.rc, it searches for a file with the equivalent UNIX-style name (that is, .exrc).


FILES

vi[lnty]nnnnn.mmm

temporary files

ex.rc

startup file (.exrc on UNIX systems)


ENVIRONMENT VARIABLES

COLUMNS

contains the number of columns between the left and right margins (see option variable wrapmargin). This is also used as the horizontal screen size.

ENV

contains the path name of a file containing MKS KornShell commands. When you invoke sh, it runs this file before doing anything else.

EXINIT

contains a list of Vi commands to be run on editor startup.

HOME

contains the directory to be searched for the editor startup file.

LINES

contains the number of lines in a screenful (see option variable window). This is also used as the vertical screen size.

PATH

contains a list of directories to be searched for the shell command specified in the Ex commands read, write, and shell.

SHELL

contains the name of the shell for use in !, shell, read, write, and other Ex commands with an operand of the form !string. The default is the sh utility.

SHELL_ERASE
SHELL_INTR
SHELL_KILL

define new values for the erase, interrupt, and line delete characters, respectively. The value of each of these variables is a single character which is ANDed with 0x1f to get a control character. For example,

SHELL_ERASE=x
sets the erase character to CTRL-X. The new erase, interrupt, and line delete characters are only in effect when using the shell command line or the vi editor.

Note:

Setting the SHELL_INTR environment variable does not stop the shell from responding to CTRL-C, since CTRL-C is processed by the console. However, the character defined by SHELL_INTR is now handled in the same manner. As well, since the SHELL_INTR value is only used by the shell command line and vi, you must still use CTRL-C to interrupt any of the programs being run.

TERM

contains the name of the terminal type.

TMP

contains the path name that MKS Toolkit uses as the directory for temporary files, if TMPDIR is not defined. TMPDIR takes precedence over TMP. If neither TMP nor TMPDIR are set, vi stores temporary files in the current directory.

TMPDIR

contains the path name that MKS Toolkit uses as the directory for temporary files.


DIAGNOSTICS

Possible exit status values are:
0

Successful completion.

1

Failure because of any of the following:

— Unknown option
— No such command from open/visual
— Missing lhs
— Missing file name
— System does not support job control
— Write forms are w and w>>
— Internal error: bad seek pointer
— Internal error: Line out of range
— Internal error: line too long
— Non-zero address required on this command
— No lines in the buffer
— Nothing to undo
— Cannot escape a newline in global from visual
— Global command too long
— Argument list too long
— File is read only
— No previous command to substitute for !
— Command too long
— No previous re or No previous regular expression
— Buffers are 1-9, a-z
— Line too long
— System does not support job control
— Digits required after =
— Nothing in buffer
— Missing rhs
— Too many macros
— Recursive map expansion
— Nothing to repeat
— Last repeatable command overflowed the repeat buffer
— Bad tag
— No tags file
— No such tag in tags file
— Negative address - first buffer line is 1
— Not an editor command
— Unimplemented Ex command
— Wrong number of addresses for command
— Mark requires following letter
— Undefined mark referenced
— Global within global not allowed
— First address exceeds second
— Cannot use open/visual unless open option is set
— Regular expression \ must be followed by / or ?
— No address allowed on this command
— No more files to edit
— No current file name
— Extra characters at end of command
— Not that many lines in buffer
— Insufficient memory
— Restricted environment
— Command too long
— Trailing address required
— Destination cannot straddle source in m and t
— No file name to substitute for %
— No alternate file name to substitute for #
— File name too long
— Too many file names
— Argument buffer overflow
— Incomplete shell escape command
— Regular expressions cannot be delimited by letters or digits
— No previous scanning regular expression
— No previous substitute to repeat
— Cannot escape newlines into regular expressions
— Missing [
— Badly constructed regular expression
— No remembered regular expression
— Line overflow in substitute
— Replacement pattern contains \d - cannot use in regular expression
— Replacement pattern too long
— Regular expression too complicated
— Cannot escape newline in visual
— No such set option
— String too long in option assignment


PORTABILITY

POSIX.2. x/OPEN Portability Guide 4.0.

The options -e and -x are extensions to the POSIX and x/OPEN standards.


LIMITS


SEE ALSO

Commands:
crypt, ctags, ed, ex, jobs, sed

Miscellaneous:
regexp, vipc


Updated MKS Toolkit [3khat16.ico]HP3000 [3khat16.ico]3kMail [archive16.gif]