vidisplay-oriented interactive text editor |
Command |
vi
[-elRsvx
] [-c
command] [-t
tag] [-w
size] [file ...]
vi
[-elRsvx
]
[+
command] [-t
tag]
[-w
size] [file ...]
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.
This indicates the real backspace key. On the PC, this has a back-arrow (->) on it. This may differ from the CTRL-H key.
This indicates the ENTER key, which is labelled RETURN on some keyboards. This may differ in effect from the CTRL-M key.
This indicates the Escape key.
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.
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.
-c
commandruns 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,
runs both the-c 'set all | ver'
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
tagedits 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
sizesets the option variable window
to size. See
section Set Option Variables
for more information.
+
commandis an obsolete version of the -c
option.
vi
uses three display conventions that should be noted.
vi
displays the input for search commands
(/
and ?
), Ex commands
(:
), and system commands (!
) on
the bottom line of the screen. Error and informational messages also
appear on this line.~
character in column one.vi
is unable to fill the
display with complete lines. In this case, one or more screen lines are
shown with a single @
character in column one.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.
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.
commands let you change the text that is already in the file.
commands let you add new text to the existing text.
count means different things with different commands. If you type count, it is not displayed anywhere on the screen.[count] command
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.
z
[m] typeredraws 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).
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.
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.
F
csearches 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.
f
csearches 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.
T
csearches 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.
t
csearches 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.
/
regexpsearches 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.
?
regexpis similar to /
, but searches backwards in the
file.
CTRL-\]
uses the word after the cursor as a tag. See tag
under Ex Commands.
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:
"
followed by the buffer name, followed by the object
manipulator command, as in
This deletes text from the current line to the bottom line on the screen and puts the deleted text in buffer"adL
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,
deletes from the current line to the bottom line on the screen, and adds the deleted text to buffer"AdL
a
.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.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.
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.
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.
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.
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.
map
and
map!
commands. See
vipc
for the symbolic names and
default programming of these keys.
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.
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
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] [[command
] [!
] [parameters]]
|
).
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.
Indicates a two address line range defaulting to the current line.
Indicates a two address line range defaulting to the entire file.
Indicates a single address defaulting to the next line.
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.
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.
'
xThe 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.
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./pattern/+3 ++ 100
command
The command
is a word, which can be abbreviated.
Characters shown in square brackets are optional. For example,
indicates that thea
[ppend
]
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.
Many Ex commands use parameters to allow you to specify more information about the command. Common parameters include:
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.
is a positive integer, specifying the number of lines to be affected by the command. If you omit count, it defaults to 1.
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.
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.
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..+5 delete 6 ++#
\
) 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.
^
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.
&
is replaced by the entire string of matched characters.
~
is replaced by the entire replacement pattern from the last substitute.
is replaced by the string that matched the nth occurrence of a
\( ... \)
in the regular expression. For example,
consider
Thes/\([a-zA-Z]*\)our/\1or/
\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
.
:
) 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.
!
) 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.
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).
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,
appends the single lineg/rhino/a\ hippo
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.
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.
!
) 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
xis 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]
xrecords 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
sets the file list to all the files in the current directory with names ending innext *.c
.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 theedit
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
In a string variable, spaces must be preceded by a backslash. As an example,name=value
shows the value of theset readonly? noautowrite shell=/bin/sh
readonly
flag, sets
noautowrite
, and sets the shell
to
/bin/sh.
shows the value of theset report report=5
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
] fileruns 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
][!
]
tagnamelooks 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).
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
] lhsThe 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
][!
]
lhsdeletes the map of lhs. If the flag !
, this applies
to the insert mode maps; otherwise it applies to the command mode
maps.
v
/pat/ commandsis 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.
undo
command to undo all changes that
occurred during the vi
command.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.
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
!
.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).
wq
[!
]
[>>
] [file]is similar to write
, except that it exits the
editor immediately afterwards (if the write is successful).
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.
edit
command does not destroy buffers, you
can use that command in conjunction with put
and
yank
to move text between files.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.
!
commandsubmits 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
sorts the entire contents of the file. Substitutions are made in command before it is run. Any occurrences of an exclamation mark (1,$!sort
!
) 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 textThis 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.
@
bufferexecutes 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.
%
), 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
to copy the current file to a safe holding place. As another example, a macro could use the percentage character (!cp % /tmp
%
) 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
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.e #
set
command. For example,
sets theset autowrite
autowrite
option. Options are turned off by putting
no
in front of the name in the set
command, as
in
In the descriptions that follow, the minimal abbreviation of each option variable is shown after the comma.set noautowrite
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.
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.
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.
noautowrite
.beautify, bf
When this option is on, the editor discards all non-printing characters from text read in from files.
The default isnobeautify
.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 isdirectory=/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.
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).
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.
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 isnoignorecase
.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 ($
).
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.
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 ismaxbuffers=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 isnonumber
.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
.
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.)
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.
-s
option.readonly
When this option is on, vi
does not let you write
to the current file.
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.
remap
.report
The editor displays a message whenever you issue a command that affects more than this number of lines.
The default isreport=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.
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
.
sections="SHNHH HU"
.shell, sh
This is the name of the shell to be used for
!
commands and the shell
command.
SHELL
environment variable.shiftwidth, sw
This sets the width of indent used by shift commands and
autoindent
.
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.
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.
noshowmode
.tabstop
Tab stops for screen display in Vi mode are set to multiples of this number.
The default istabstop=8
taglength, tl
If this variable is non-zero, tags are only compared for this number of characters.
The default istaglength=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:
These are used by theset tags=file1\ file2\ file3\
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.
TheTERM
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 isnoterse
.visualbell
When this option is on, vi
flashes your screen as
the visual equivalent of the alert character.
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.
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.
-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 iswrapmargin=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 iswrapscan
.writeany, wa
If this option is off, the editor does not let a file marked
[Not edited]
overwrite an existing file.
nowriteany
.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.
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.
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.
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.
If vi
does not find a file named ex.rc
,
it searches for a file with the equivalent UNIX-style name (that is,
.exrc
).
vi[lnty]nnnnn.mmm
temporary files
ex.rc
startup file (.exrc
on UNIX systems)
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,
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 theSHELL_ERASE=x
vi
editor.
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.
0
Successful completion.
1
Failure because of any of the following:
w
and
w>>
!
=
\
must be followed by
/
or ?
m
and t
%
#
[
\d
- cannot
use in regular expression-e
and -x
are extensions
to the POSIX and x/OPEN standards.
map
, map!
and
abbreviate
entries: 128 each..
in Vi: 128.map
,
map!
, or abbreviate
: No fixed
limit. Limit is based on available memory.:
escape from Vi: 256.maxbuffers
K of
auxiliary memory. During startup, maxbuffers
is changed to
reflect available memory; at least 32K is required.