.\" The Regents of the University of California. All rights reserved.
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\" 3. All advertising materials mentioning features or use of this software
.\" must display the following acknowledgement:
.\" This product includes software developed by the University of
.\" California, Berkeley and its contributors.
.\" 4. Neither the name of the University nor the names of its contributors
.\" may be used to endorse or promote products derived from this software
.\" without specific prior written permission.
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" @(#)vi.ref 8.19 (Berkeley) 3/18/94
.Dt "EX/VI REFERENCE MANUAL" 1
is a screen oriented text editor.
is a line-oriented text editor.
are different interfaces to the same program,
and it is possible to switch back and forth during an edit session.
is the equivalent of using the
This reference manual is the one provided with the
are intended as bug-for-bug compatible replacements for the original
Fourth Berkeley Software Distribution (4BSD)
This reference manual is accompanied by a traditional-style manual page.
That manual page describes the functionality found in
in far less detail than the description here.
In addition, it describes the system interface to
e.g. command line options, environmental variables, and similar things.
This reference is intended for users already familiar with
Anyone else should almost certainly read a good tutorial on the
If you're in an unfamiliar environment, and you absolutely have to
get work done immediately, see the section entitled FAST STARTUP
It's probably enough to get you going.
For the rest of this reference,
is used only when it's necessary to distinguish it from the historic
There are a few features in
that are not found in historic versions of
A list of those features is as follows:
.It "8-bit clean data, large lines, files"
will edit any format file.
Line lengths are limited by available memory,
and file sizes are limited by available disk space.
in input mode, will insert any
legal character value into the text.
.Dq ":sp[lit] [file ...]"
splits the screen in vi mode.
switches between the foreground screens,
command can be used to grow or shrink a particular screen.
.It "Background and foreground screens"
backgrounds the current screen,
foregrounds the backgrounded screen
that is editing the specified file, or, by default, the first background
.Dq ":di[splay] s[creens]"
lists the background screens.
.Dq ":sc[ript] [file ...]"
runs a shell in the screen.
Editing is unchanged, with the exception that a <carriage-return>
enters the current line (stripped of any prompt) as input to the
Tags are now maintained in a stack.
returns to the previous tag location.
.Dq ":tagpop [number \| file]"
returns to the most recent tag
location by default, or, optionally to a specific tag number in the
tag stack, or the most recent tag from the specified file.
returns to the top of the tag stack.
.Dq ":di[splay] b[uffers] \| s[creens] \| t[ags]"
used to display, respectively, the current cut buffers,
the backgrounded screens, and the tags stack.
The changes made during an edit session may be rolled backward and
A '.' command immediately after a 'u' command continues either forward
or backward depending on whether the 'u' command was an undo or a redo.
information for all of the ex and vi commands by default, or, optionally,
for a specific command or key.
.It "Extended regular expressions"
command treats search and other command regular
expressions as extended (egrep(1) style) regular expressions.
searches for the word referenced by the cursor.
increments the number referenced by the cursor.
edits the previous file from the
.It "Left-Right scrolling"
do left-right screen scrolling, instead of the traditional
There is no recovery program for
Users may recover any file which they may read, and the superuser
may recover any edit session.
Edit sessions are backed by files in
.Pa /var/tmp/vi.recover ,
is a number related to the process id.
When a file is first modified, a second file, which contains an
email message for the user, is created, and is named
is associated with the process id.
Both files are removed at the end of a normal edit session,
but will remain if the edit session is abnormally terminated
or the user enters the ex/vi
directory may be changed setting the
option in the user's or system startup information.
The recovery directory should have the
set so that only the owners of files may remove them.
If this is not possible on the system, then a pseudo-user should
own the recovery directory.
The recovery directory must be both read and write-able by
The recovery file has all of the necessary information in it to enable the
user to recover the edit session.
In addition, it has all of the necessary email headers for sendmail.
When the system is rebooted, all of the files in
flag of sendmail (or a similar mechanism in other mailers).
A simple way to do this is to insert the following script into your
.Bd -literal -offset indent -compact
# Recover vi editor files.
virecovery=`echo /var/tmp/vi.recover/recover.*`
if [ "$virecovery" != "/var/tmp/vi.recover/recover.*" ]; then
echo 'Recovering vi editor sessions'
receives a hangup (SIGHUP) signal, it will email the recovery
information to the user itself.
If you don't have the sendmail program on your system, the source file
will have to be modified to use your local mail delivery programs.
interprets one of two possible environmental variables and reads up
to three of five possible files during startup.
The variables and files are expected to contain
In addition, they are interpreted
the file to be edited is read, and therefore many
commands may not be used.
Generally, any command that requires output to the screen or that
needs a file upon which to operate, will cause an error if included
in a startup file or environmental variable.
Second, the environmental variable
Startup files will not be read if they are owned by anyone other
than the real user-id of the user running
or if they are writable by anyone other than the owner.
Home directory startup file (i.e.
environmental variable is not set.
The local startup file (i.e.
option is turned off in the
It is not an error for any of the startup environmental variables
is a superset of the command set supported by most historical implementations
can use the startup files created for the historical implementations,
but the converse is often not true.
The size of the screen can be set in a number of ways.
takes the following steps until values are obtained for both the
number of rows and number of columns in the screen.
If the environmental variable
exists, it is used to specify the number of rows in the screen.
If the environmental variable
exists, it is used to specify the number of columns in the screen.
is attempted on the standard error file descriptor.
The termcap entry is checked for the
The number of rows is set to 24, and the number of columns is set
If a window change size signal (SIGWINCH) is received,
the same steps are taken with the exception that the first two steps
.Sh REGULAR EXPRESSIONS AND REPLACEMENT STRINGS
Regular expressions are used in line addresses,
The regular expressions supported by
are, by default, the Basic Regular Expressions (BRE's) described in the
IEEE POSIX Standard 1003.2.
option causes all regular expressions to be interpreted as the Extended
Regular Expressions (ERE's) described by the same standard.
Generally speaking, BRE's are
style regular expressions, and ERE's are
style regular expressions.)
There are some special strings and characters that can be used in
is equivalent to the last RE used.
matches the beginning of a word.
matches the end of a word.
matches the replacement part of the last
the only characters with special meanings are
at the beginning of an RE,
at the end of an RE, and the escaping character
are treated as ordinary characters unless preceded by a
they regain their special meaning.
Replacement strings are the second part of a
set) in the replacement string stands for the text matched by the RE
set) stands for the replacement part of the previous
is an integer value from 1 to 9, stands for the text matched by
the portion of the RE enclosed in the #'th set of escaped parentheses,
.Dq "s/abc\e(.*\e)def/\e1/"
from the matched pattern.
can be used to modify the case of elements in the replacement string.
causes the next character to be converted to lowercase; the string
behaves similarly, but converts to uppercase.
causes characters up to the end of the string or the next occurrence of
to be converted to lowercase; the string
behaves similarly, but converts to uppercase.
inserting a <control-M> into the replacement string will cause the
matched line to be split into two lines at that point.