Vi is a screen oriented text editor. Ex is a line-oriented text editor. Ex and vi are different interfaces to the same program, and it is possible to switch back and forth during an edit session. View is the equivalent of using the -R (read-only) option of vi .
This reference manual is the one provided with the nex/nvi versions of the ex/vi text editors. Nex/nvi are intended as bug-for-bug compatible replacements for the original Fourth Berkeley Software Distribution (4BSD) ex/vi programs. This reference manual is accompanied by a traditional-style manual page. That manual page describes the functionality found in ex/vi in far less detail than the description here. In addition, it describes the system interface to ex/vi, e.g. command line options, session recovery, signals, environmental variables, and similar things.
This reference is intended for users already familiar with ex/vi. Anyone else should almost certainly read a good tutorial on the editor first. If you are in an unfamiliar environment, and you absolutely have to get work done immediately, see the section entitled "Fast Startup" in the manual page. It is probably enough to get you started.
There are a few features in nex/nvi that are not found in historic versions of ex/vi. Some of the more interesting of those features are briefly described in the next section, entitled "Additional Features" . For the rest of this document, nex/nvi is used only when it is necessary to distinguish it from the historic implementations of ex/vi.
Future versions of this software will be periodically made available
by anonymous ftp, and can be retrieved from
ftp.cs.berkeley.edu
,
in the directory
ucb/4bsd
.
There are a few features in nex/nvi that are not found in historic versions of ex/vi. Some of the more interesting of these are as follows:
Nex/nvi will edit any format file. Line lengths are limited by available memory, and file sizes are limited by available disk space. The vi text input mode command <control-X> can insert any possible character value into the text.
The bg command backgrounds the current screen, and the fg command foregrounds backgrounded screens. The display command can be used to list the background screens.
You can enter a normal editing window on the collected commands that
you've entered on the
vi
colon command-line,
and then modify and/or execute the commands.
See the
cedit
edit option for more information.
The display command can be used to display the current buffers, the backgrounded screens, and the tags stack.
The
extended
option causes Regular Expressions to be interpreted as as Extended
Regular Expressions, (i.e. egrep
(1) style Regular Expressions).
It is possible to do file name completion and file name displays when
entering commands on the
vi
colon command-line.
See the
filec
option for more information.
Changes made during an edit session may be rolled backward and forward. A . command immediately after a u command continues either forward or backward depending on whether the u command was an undo or a redo.
The leftright option causes nvi to do left-right screen scrolling, instead of the traditional vi line wrapping.
It is possible to display informational and error messages in different
languages by providing a catalog of messages.
See the
msgcat
option and the file
catalog/README
for more information.
The # command increments or decrements the number referenced by the cursor.
The previous command edits the previous file from the argument list.
The :pe[rl] cmd, :perld[o] cmd and :tc[l] cmd commands execute Perl and Tcl/Tk commands, respectively, on lines from the edit buffer. See the "Scripting Languages" section and the specific commands for more information.
The Edit , Ex , Next , Previous , Tag and Visual (in vi mode) commands divide the screen into multiple editing regions and then perform their normal function in a new screen area. The <control-W> command rotates between the foreground screens. The resize command can be used to grow or shrink a particular screen.
Tags are now maintained in a stack. The <control-T> command returns to the previous tag location. The tagpop command 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 a specified file. The display command can be used to list the tags stack. The tagtop command returns to the top of the tag stack.
The exusage and viusage commands provide usage information for all of the ex and vi commands by default, or, optionally, for a specific command or key.
The <control-A> command searches for the word referenced by the cursor.
Ex/vi 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 ex commands, not vi commands. In addition, they are interpreted before the file to be edited is read, and therefore many ex 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.
Because the ex command set supported by nex/nvi is a superset of the command set supported by historical implementations of ex , nex/nvi can use the startup files created for the historical implementations, but the converse may not be true.
If the -s (the historic - option) is specified, or if standard input is redirected from a file, all environmental variables and startup files are ignored.
Otherwise, startup files and environmental variables are handled in the following order:
/etc/vi.exrc
is read,
as long as it is owned by root or the effective user ID of the user.
NEXINIT
(or the variable
EXINIT
,
if
NEXINIT
is not set) is interpreted.
NEXINIT
or
EXINIT
was set, and the
HOME
environmental variable is set, the file
$HOME/.nexrc
(or the file
$HOME/.exrc
,
if
$HOME/.nexrc
does not exist) is read,
as long as the effective user ID of the user is root or is the same as
the owner of the file.
When the $HOME directory is being used for both
nex/nvi
and an historic implementation of
ex/vi,
a possible solution is to put
nex/nvi
specific commands in the
.nexrc
file, along with a
:source $HOME/.exrc
command to read in the commands common to both implementations.
exrc
option was turned on by one of the previous startup information
sources, the file
.nexrc
(or the file
.exrc
,
if
.nexrc
does not exist) is read, as long as the effective user ID of the user
is the same as the owner of the file.
No startup file is read if it is writable by anyone other than its owner.
It is not an error for any of the startup environmental variables or files not to exist.
Once all environmental variables are interpreted, and all startup files are read, the first file to be edited is read in (or a temporary file is created). Then, any commands specified using the -c option are executed, in the context of that file.
There is no recovery program for nex/nvi, nor does nex/nvi run setuid. Recovery files are created readable and writable by the owner only. Users may recover any file which they can read, and the superuser may recover any edit session.
Edit sessions are backed by files in the directory named by the
recdir
option (the directory
/var/tmp/vi.recover
by default), and are named
"vi.XXXXXX",
where
"XXXXXX"
is a number related to the process ID.
When a file is first modified,
a second recovery file containing an email message for the user is created,
and is named
"recover.XXXXXX",
where, again,
"XXXXXX"
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 runs the
ex
preserve
command.
The
recdir
option may be set in either the user's or system's startup information,
changing the recovery directory.
(Note, however, that if a memory based file system is used as the backup
directory, each system reboot will delete all of the recovery files!
The same caution applies to directories such as
/tmp
which are cleared of their contents by a system reboot, or
/usr/tmp
which is periodically cleared of old files on many systems.)
The recovery directory should be owned by root, or at least by a pseudo-user. In addition, if directory "sticky-bit" semantics are available, the directory should have the sticky-bit set so that files may only be removed by their owners. The recovery directory must be read, write, and executable by any user, i.e. mode 1777.
If the recovery directory does not exist, ex/vi will attempt to create it. This can result in the recovery directory being owned by a normal user, which means that that user will be able to remove other user's recovery and backup files. This is annoying, but is not a security issue as the user cannot otherwise access or modify the files.
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
(8).
When the system is rebooted, all of the files in
/var/tmp/vi.recover
named
"recover.XXXXXX"
should be sent to their owners, by email, using the
-t
option of
sendmail
(or a similar mechanism in other mailers).
If
ex/vi
receives a hangup (SIGHUP) signal, or the user executes the
ex
preserve
command,
ex/vi
will automatically email the recovery information to the user.
If your system does not have the
sendmail
utility (or a mailer program which supports its interface)
the source file
nvi/common/recover.c
will have to be modified to use your local mail delivery programs.
Note, if
nex/nvi
is changed to use another mailer,
it is important to remember that the owner of the file given to
the mailer is the
nex/nvi
user, so nothing in the file should be trusted as it may have been
modified in an effort to compromise the system.
Finally, the owner execute bit is set on backup files when they are created, and unset when they are first modified, e.g. backup files that have no associated email recovery file will have this bit set. (There is also a small window where empty files can be created and not yet have this bit set. This is due to the method in which the files are created.) Such files should be deleted when the system reboots.
A simple way to do this cleanup is to run the Bourne shell script
recover ,
from your
/etc/rc.local
(or other system startup) file.
The script should work with the historic Bourne shell,
a POSIX 1003.2 shell or the Korn shell.
The
recover
script is installed as part of the
nex/nvi
installation process.
Consult the manual page for details on recovering preserved or aborted editing sessions.
The size of the screen can be set in a number of ways. Ex/vi takes the following steps until values are obtained for both the number of rows and number of columns in the screen.
LINES
exists,
it is used to specify the number of rows in the screen.
COLUMNS
exists,
it is used to specify the number of columns in the screen.
ioctl
(2)
is attempted on the standard error file descriptor.
If a window change size signal (SIGWINCH) is received,
the new window size is retrieved using the TIOCGWINSZ
ioctl
(2)
call, and all other information is ignored.
In both
ex
and
vi
printable characters as defined by
isprint
(3)
are displayed using the local character set.
Non-printable characters, for which
iscntrl
(3)
returns true, and which are less than octal \e040,
are displayed as the string
"^<character>
",
where
<character>
is the character that is the original character's value offset from the
"@
"
character.
For example, the octal character \e001 is displayed as
"^A
".
If
iscntrl
(3)
returns true for the octal character \e177,
it is displayed as the string
"^?
".
All other characters are displayed as either hexadecimal values,
in the form
"0x<high-halfbyte> ... 0x<low-halfbyte>
",
or as octal values, in the form
"e<high-one-or-two-bits> ... e<low-three-bits>
".
The display of unknown characters is based on the value of the
octal
option.
In vi command mode, the cursor is always positioned on the last column of characters which take up more than one column on the screen. In vi text input mode, the cursor is positioned on the first column of characters which take up more than one column on the screen.
Nvi supports multiple screens by dividing the window into regions. It also supports stacks of screens by permitting the user to change the set of screens that are currently displayed.
The Edit , Ex , Fg , Next , Previous , Tag and Visual (in vi mode) commands divide the current screen into two regions of approximately equal size and then perform their usual action in a new screen area. If the cursor is in the lower half of the screen, the screen will split up, i.e. the new screen will be above the old one. If the cursor is in the upper half of the screen, the new screen will be below the old one.
When more than one screen is editing a file, changes in any screen are reflected in all other screens editing the same file. Exiting a screen without saving any changes (or explicitly discarding them) is permitted until the last screen editing the file is exited, at which time the changes must be saved or discarded.
The resize command permits resizing of individual screens. Screens may be grown, shrunk or set to an absolute number of rows.
The ^W command is used to switch between screens. Each ^W moves to the next lower screen in the window, or to the first screen in the window if there are no lower screens.
The bg command "backgrounds" the current screen. The screen disappears from the window, and the rows it occupied are taken over by a neighboring screen. It is an error to attempt to background the only screen in the window.
The display screens command displays the names of the files associated with the current backgrounded screens in the window.
The fg [file] command moves the specified screen from the list of backgrounded screens to the foreground. If no file argument is specified, the first screen on the list is foregrounded. By default, foregrounding consists of backgrounding the current screen, and replacing its space in the window with the foregrounded screen.
Capitalizing the first letter of the command, i.e. Fg , will foreground the backgrounded screen in a new screen instead of swapping it with the current screen.
If the last foregrounded screen in the window is exited, and there are backgrounded screens, the first screen on the list of backgrounded screens takes over the window.
Nvi
supports the historic
vi
tag command
<control-]> ,
and the historic
ex
tag command
tag .
These commands change the current file context to a new location,
based on information found in the
tags
files.
If you are unfamiliar with these commands,
you should review their description in the
ex
and
vi
commands section of this manual.
For additional information on tags files,
see the discussion of the
tags
edit option and the system
ctags
(1)
manual page.
In addition, nvi supports the notion of "tags stacks", using the <control-T> command. The <control-T> command returns the user to the previous context, i.e., the last place from which a <control-]> or tag command was entered. These three commands provide the basic functionality which allows you to use vi to review source code in a structured manner.
Nvi also provides two other basic ex commands for tag support: tagpop and tagtop . The tagpop command is identical to the <control-T> command, with the additional functionality that you may specify that modifications to the current file are to be discarded. This cannot be done using the <control-T> command. The tagtop command discards all of the contexts that have been pushed onto the tag stack, returning to the context from which the first <control-]> or tag command was entered.
The historic
ctags
(1)
tags file format supports only a single location per tag,
normally the function declaration or structure or string definition.
More sophisticated source code tools often provide multiple locations
per tag, e.g.,
a list of the places from which a function is called or a string
definition is used.
An example of this functionality is the System V source code tool,
cscope .
Cscope
creates a database of information on source code files,
and supports a query language for that information as described in the
cscope
(1)
manual page.
Nvi
contains an interface to the
cscope
query language which permits you to query
cscope
and then sequentially step through the locations in the sources files which
cscope
returns.
There are two
nvi
commands which support this ability to step through multiple locations.
They are the
ex
commands
tagnext
and
tagprev .
The
tagnext
command moves to the next location for the current tag.
The
tagprev
command moves to the previous location for the current tag.
(See the
tagnext
and
tagprev
command discussion in the
ex
commands section of this manual for more information.)
At any time during this sequential walk,
you may use the
<control-]> ,
tag
or
cscope
commands to move to a new tag context, and then use the
<control-T>
or
tagpop
commands to return and continue stepping through the locations for this
tag.
This is similar to the previous model of a simple tag stack,
except that each entry in the tag stack may have more than one file context
that is of interest.
Although there is no widely distributed version of
ctags
(1)
that creates tags files with multiple locations per tag,
nvi
has been written to understand the obvious extension to the historic
tags file format, i.e., more than a single line in the tags file with
the same initial tag name.
If you wish to extend your
ctags
implementation or other tool with which you build tags files,
this extension should be simple and will require no changes to
nvi .
The nvi and cscope interface is based on the new ex command cscope , which has five subcommands: add , find , help , kill and reset . The subcommand find itself has eight subcommands: c , d , e , f , g , i , s and t .
The add command attaches to the specified cscope database. The file name is expanded using the standard filename expansions. If file is a directory, the file "cscope.out" in that directory is used as the database.
After
nvi
attaches to a new database,
all subsequent
cscope
queries will be asked of that database.
The result of any single query is the collection of response to the query
from all of the attached databases.
If the "CSCOPE_DIRS" environmental variable is set when nvi is run, it is expected to be a <colon> or <blank>-separated list of cscope databases or directories containing cscope databases, to which the user wishes to attach.
The
find
command is the
cscope
query command for
nvi .
For this command,
nvi
queries all attached
cscope
databases for the pattern.
If the pattern is a double-quote character followed by a valid buffer
name (e.g.,
"<character>" ),
then the contents of the named buffer are used as the pattern.
Otherwise, the pattern is a Regular Expression.
The
find
command pushes the current location onto the tags stack,
and switches to the first location resulting from the query,
if the query returned at least one result.
File names returned by the
cscope
query, if not absolute paths, are searched for relative to the directory
where the
cscope
database is located.
In addition, if the file
"cscope.tpath"
appears in the same directory as the
cscope
database,
it is expected to contain a colon-separated list of directory names
where files referenced by its associated
cscope
database may be found.
The find subcommand is one of the following:
List the cscope commands, or optionally list usage help for any single cscope command.
Display the list of cscope databases to which nvi is currently connected.
Disconnect from a specific cscope database. The connection number is the one displayed by the ex display connections command.
Disconnect from all attached cscope databases.
Cscope is not freely redistributable software, but is fairly inexpensive and easily available. To purchase a copy of cscope , see http://www.att.com/ssg/products/toolchest.html.
Regular expressions are used in line addresses, as the first part of the ex substitute , global , and v commands, and in search patterns.
The regular expressions supported by
ex/vi
are, by default, the Basic Regular Expressions (BRE's) described in the
IEEE POSIX Standard 1003.2.
The
extended
option causes all regular expressions to be interpreted as the Extended
Regular Expressions (ERE's) described by the same standard.
(See
re_format
(7)
for more information.)
Generally speaking, BRE's are the Regular Expressions found in
ed
(1)
and
grep
(1),
and ERE's are the Regular Expressions found in
egrep
(1).
The following is not intended to provide a description of Regular Expressions. The information here only describes strings and characters which have special meanings in the ex/vi version of RE's, or options which change the meanings of characters that normally have special meanings in RE's.
//
"
or
"??
"
is equivalent to the last RE used.
e<
"
matches the beginning of a word.
e>
"
matches the end of a word.
~
"
matches the replacement part of the last
substitute
command.
When the
magic
option is
not
set, the only characters with special meanings are a
"^
"
character at the beginning of an RE, a
"$
"
character at the end of an RE, and the escaping character
"e
".
The characters
".
",
"*
",
"[
"
and
"~
"
are treated as ordinary characters unless preceded by a
"e
";
when preceded by a
"e
"
they regain their special meaning.
Replacement strings are the second part of a substitute command.
The character
"&
"
(or
"e&
"
if the
magic
option is
not
set) in the replacement string stands for the text matched by the RE
that is being replaced.
The character
"~
"
(or
"e~
"
if the
magic
option is
not
set) stands for the replacement part of the previous
substitute
command.
It is only valid after a
substitute
command has been performed.
The string
"e#
",
where
"#
"
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, e.g.
"e(
"
and
"e)
".
For example,
"s/abce(.*e)def/e1/
"
deletes the strings
"abc
"
and
"def
"
from the matched pattern.
The strings
"el
",
"eu
",
"eL
"
and
"eU
"
can be used to modify the case of elements in the replacement string.
The string
"el
"
causes the next character to be converted to lowercase;
the string
"eu
"
behaves similarly, but converts to uppercase
(e.g.
s/abc/eU&/
replaces the string
abc
with
ABC
).
The string
"eL
"
causes characters up to the end of the string or the next occurrence
of the strings
"ee
"
or
"eE
"
to be converted to lowercase;
the string
"eU
"
behaves similarly, but converts to uppercase.
If the entire replacement pattern is
"%
",
then the last replacement pattern is used again.
In
vi ,
inserting a
<control-M>
into the replacement string will cause
the matched line to be split into two lines at that point.
(The
<control-M>
will be discarded.)
The nvi editor currently supports two scripting languages, Tcl/Tk and Perl. (Note that Perl4 isn't sufficient, and that the Perl5 used must be version 5.002 or later. See the "Building Nvi" section for more information.
The scripting language interface is still being worked on,
therefore the following information is probably incomplete,
probably wrong in cases, and likely to change.
See the
perl_api
and
tcl_api
source directories for more information.
As a quick reference, the following function calls are provided for
both the Perl and Tcl interfaces.
The Perl interface uses a slightly different naming convention,
e.g. "viFindScreen" is named "VI::FindScreen".
Return the
screenId
associated with
file
.
Append
text
as a new line after line number
lineNumber
,
in the screen
screenId
.
Delete the line
lineNumber
from the screen
screenId
.
Return the line
lineNumber
from the screen
screenId
.
Insert
text
as a new line before line number
lineNumber
in the screen
screenId
.
Return the line number of the last line in the screen
screenId
.
Change the line
lineNumber
in the screen
screenId
to match the specified
text
.
Return the current line and column for the specified
mark
from the screen
screenId
.
Set the specified
mark
to be at line
line
,
column
column
,
in the screen
screenId
.
Return the current line and column for the cursor in the screen
screenId
.
Set the cursor in the screen
screenId
to the specified
line
and
column
.
Display the specified
text
as a vi message in the screen
screenId
.
Create a new screen.
Exit the screen
screenId
.
Switch from the screen
screenId
to the screen
screenId
.
Map the specified
key
in the screen
screenId
to the Tcl procedure
tclproc
.
Unmap the specified
key
in the screen
screenId
Return the value of the specified
option
from the screen
screenId
.
Set one or more options in the screen
screenId
.
When
ex
or
vi
are executed,
the text of a file is read (or a temporary file is created),
and then all editing changes happen within the context of the
copy of the file.
No changes affect the actual file until the file is written out,
either using a write command or another command which is affected by the
autowrite
option.
All files are locked (using the
flock
(2)
or
fcntl
(2)
interfaces) during the edit session,
to avoid inadvertently making modifications to multiple copies of the file.
If a lock cannot be obtained for a file because it is locked by another
process, the edit session is read-only (as if the
readonly
option or the
-R
flag had been specified).
If a lock cannot be obtained for other reasons, the edit session will
continue, but the file status information
(see the
<control-G>
command) will reflect this fact.
Both
ex
and
vi
are modeful editors, i.e. they have two modes,
"command"
mode and
"text input"
mode.
The former is intended to permit you to enter commands which modifies
already existing text.
The latter is intended to permit you to enter new text.
When
ex
first starts running, it is in command mode, and usually displays a prompt
(see the
prompt
option for more information).
The prompt is a single colon
":
"
character.
There are three commands that switch
ex
into text input mode:
append ,
change
and
insert .
Once in input mode, entering a line containing only a single period
".
"
ends text input mode and returns to command mode,
where the prompt is redisplayed.
When
vi
first starts running, it is in command mode as well.
There are eleven commands that switch
vi
into text input mode:
A ,
a ,
C ,
c ,
I ,
i ,
O ,
o ,
R ,
S
and
s .
Once in input mode, entering an
<escape>
character ends text input mode and returns to command mode.
Ex/vi present three different interfaces to editing a file. Ex presents a line oriented interface. Vi presents a full screen display oriented interface, also known as "visual mode". In addition, there is a third mode, "open mode", which is line oriented, but supports cursor movement and editing within the displayed line, similarly to visual mode. Open mode is not yet implemented in nvi .
The following words have special meanings in both the ex and vi command descriptions:
The interrupt character is used to interrupt the current operation.
Normally
<control-C>
,
whatever character is set for the current terminal is used.
The literal next character is used to escape the subsequent character
from any special meaning.
This character is always
<control-V>
.
If the terminal is not set up to do XON/XOFF flow control,
then
<control-Q>
is used to mean literal next as well.
The pathname of the file currently being edited by vi.
When the percent character
"%
"
appears in a file name entered as part of an
ex
command argument, it is replaced by the current pathname.
(The
"%
"
character can be escaped by preceding it with a backslash.)
The name of the last file name mentioned in an
ex
command, or,
the previous current pathname if the last file mentioned
becomes the current file.
When the hash mark character
"#
"
appears in a file name entered as part of an
ex
command argument, it is replaced by the alternate pathname.
(The
"#
"
character can be escaped by preceding it with a backslash.)
One of a number of named areas for saving copies of text.
Commands that change or delete text can save the changed or deleted
text into a specific buffer, for later use, if the command allows
it (i.e. the
ex
change
command cannot save the changed text in a named buffer).
Buffers are named with a single character, preceded by a double quote,
e.g.
"<character>"
in
vi
and
without the double quote, e.g.
<character>
,
in
ex .
(The double quote isn't necessary for
ex
because buffers names are denoted by their position in the command line.)
Historic implementations of
ex/vi
limited
<character>
to the alphanumeric characters;
nex/nvi
permits the use of any character without another meaning in the position
where a buffer name is expected.
Buffers named by uppercase characters are the same as buffers
named by lowercase characters, e.g. the buffer named by the
English character
"A
"
is the same as the buffer named by the character
"a
",
with the exception that, if the buffer contents are being changed (as
with a text deletion or
vi
change
command), the text is
appended
to the buffer, instead of replacing the current contents.
The buffers named by the numeric characters (in English,
"1
"
through
"9
"),
are special.
If a region of text including characters from more than one line,
or a single line of text specified by using a line-oriented motion,
is changed or deleted in the file using the
vi
change
or
delete
commands, a copy of the text is placed into the numeric buffer
"1
",
regardless of the user specifying another buffer in which to save it.
In addition, there are a few commands which, when used as a
motion
with the
vi
change
and
delete
commands,
always
copy the specified region of text into the numeric buffers regardless
of the region including characters from more than one line.
These commands are:
<control-A> | % | ( | )
|
`<character> | / | ? | N
|
n | { | }
|
Before this copy is done, the previous contents of buffer
"1
"
are moved into buffer
"2
",
"2
"
into buffer
"3
",
and so on.
The contents of buffer
"9
"
are discarded.
In
vi ,
text may be explicitly stored into the numeric buffers.
In this case, the buffer rotation described above occurs before the
replacement of the buffer's contents.
The numeric buffers are only available in
visual
and
open
modes,
and are not accessible by
ex
in any way, although changed and deleted text is still stored there
while in
ex
mode.
When a
vi
command synopsis shows both a
[buffer]
and a
[count]
,
they may be presented in any order.
Finally, all buffers are either "line" or "character" oriented. All ex commands which store text into buffers are line oriented. Some vi commands which store text into buffers are line oriented, and some are character oriented; the description for each applicable vi command notes whether text copied into buffers using the command is line or character oriented. In addition, the vi command display buffers displays the current orientation for each buffer. Generally, the only importance attached to this orientation is that if the buffer is subsequently inserted into the text, line oriented buffers create new lines for each of the lines they contain, and character oriented buffers create new lines for any lines other than the first and last lines they contain. The first and last lines are inserted into the text at the current cursor position, becoming part of the current line. If there is more than one line in the buffer, however, the current line itself will be split.
The unnamed buffer is a text storage area which is used by commands
that use or operate on a buffer when no buffer is specified by the user.
If the command stores text into a buffer,
the text is stored into the unnamed buffer even if a buffer is also
specified by the user.
It is not possible to append text to the unnamed buffer.
If text is appended to a named buffer,
the named buffer contains both the old and new text,
while the unnamed buffer contains only the new text.
There is no way to explicitly reference the unnamed buffer.
Historically, the contents of the unnamed buffer were discarded by many different commands, even ones that didn't store text into it. Nex/nvi never discards the contents of the unnamed buffer until new text replaces them.
The characters <tab> and <space>.
The character represented by an ASCII
<control-M>
.
This character is almost always treated identically to a
<newline>
character, but differs in that it can be escaped into the file text or
into a command.
The character represented by an ASCII
<control-J>
.
This character is almost always treated identically to a
<control-M>
character, but differs in that it cannot be escaped into the file text or
into a command.
Vi takes up the entire screen to display the edited file,
except for the bottom line of the screen.
The bottom line of the screen is used to enter
exp
commands, and for
vi
error and informational messages.
If no other information is being displayed,
the default display can show the current cursor row and cursor column,
an indication of whether the file has been modified,
and the current mode of the editor.
See the
ruler
and
showmode
options for more information.
Empty lines do not have any special representation on the screen,
but lines on the screen that would logically come after the end of
the file are displayed as a single tilde
"~
"
character.
To differentiate between empty lines and lines consisting of only
whitespace characters, use the
list
option.
Historically, implementations of
vi
have also displayed some lines as single asterisk
"@
"
characters.
These were lines that were not correctly displayed, i.e. lines on the
screen that did not correspond to lines in the file, or lines that did
not fit on the current screen.
Nvi
never displays lines in this fashion.
Vi
is a modeful editor, i.e. it has two modes,
"command"
mode and
"text input"
mode.
When
vi
first starts, it is in command mode.
There are several commands that change
vi
into text input mode.
The
<escape>
character is used to resolve the text input into the file,
and exit back into command mode.
In
vi
command mode, the cursor is always positioned on the last column of
characters which take up more than one column on the screen.
In
vi
text insert mode, the cursor is positioned on the first column of
characters which take up more than one column on the screen.
When positioning the cursor to a new line and column,
the type of movement is defined by the distance to the new cursor position.
If the new position is close,
the screen is scrolled to the new location.
If the new position is far away,
the screen is repainted so that the new position is on the screen.
If the screen is scrolled,
it is moved a minimal amount,
and the cursor line will usually appear at the top or bottom of the screen.
If the screen is repainted,
the cursor line will appear in the center of the screen,
unless the cursor is sufficiently close to the beginning or end of the file
that this isn't possible.
If the
leftright
option is set, the screen may be scrolled or repainted in a horizontal
direction as well as in a vertical one.
A major difference between the historical vi presentation and nvi is in the scrolling and screen oriented position commands, <control-B>, <control-D>, <control-E>, <control-F>, <control-U>, <control-Y>, H, L and M. In historical implementations of vi, these commands acted on physical (as opposed to logical, or screen) lines. For lines that were sufficiently long in relation to the size of the screen, this meant that single line scroll commands might repaint the entire screen, scrolling or screen positioning commands might not change the screen or move the cursor at all, and some lines simply could not be displayed, even though vi would edit the file that contained them. In nvi, these commands act on logical, i.e. screen lines. You are unlikely to notice any difference unless you are editing files with lines significantly longer than a screen width.
Vi keeps track of the currently "most attractive" cursor position. Each command description (for commands that alter the current cursor position), specifies if the cursor is set to a specific location in the line, or if it is moved to the "most attractive cursor position". The latter means that the cursor is moved to the cursor position that is horizontally as close as possible to the current cursor position. If the current line is shorter than the cursor position vi would select, the cursor is positioned on the last character in the line. (If the line is empty, the cursor is positioned on the first column of the line.) If a command moves the cursor to the most attractive position, it does not alter the current cursor position, and a subsequent movement will again attempt to move the cursor to that position. Therefore, although a movement to a line shorter than the currently most attractive position will cause the cursor to move to the end of that line, a subsequent movement to a longer line will cause the cursor to move back to the most attractive position.
In addition, the $ command makes the end of each line the most attractive cursor position rather than a specific column.
Each vi command described below notes where the cursor ends up after it is executed. This position is described in terms of characters on the line, i.e. "the previous character", or, "the last character in the line". This is to avoid needing to continually refer to on what part of the character the cursor rests.
The following words have special meaning for vi commands.
The position of the cursor before the command which caused the last absolute movement was executed. Each vi command described in the next section that is considered an absolute movement is so noted. In addition, specifying any address to an ex command is considered an absolute movement.
A second
vi
command can be used as an optional trailing argument to the
vi
<,
>,
!,
c,
d,
y,
and (depending on the
tildeop
option)
~
commands.
This command indicates the end of the region of text that's affected by
the command.
The motion command may be either the command character repeated (in
which case it means the current line) or a cursor movement command.
In the latter case, the region affected by the command is from the
starting or stopping cursor position which comes first in the file,
to immediately before the starting or stopping cursor position which
comes later in the file.
Commands that operate on lines instead of using beginning and ending
cursor positions operate on all of the lines that are wholly or
partially in the region.
In addition, some other commands become line oriented depending on
where in the text they are used.
The command descriptions below note these special cases.
The following commands may all be used as motion components for
vi
commands:
<control-A> | <control-H> | <control-J> | <control-M>
|
<control-N> | <control-P> | <space> | $
|
% | '<character> | ( | )
|
+ | , | - | /
|
0 | ; | ? | B
|
E | F | G | H
|
L | M | N | T
|
W | [[ | ]] | ^
|
_ | `<character> | b | e
|
f | h | j | k
|
l | n | t | w
|
{ | | | }
|
The optional count prefix available for some of the
vi
commands that take motion commands,
or the count prefix available for the
vi
commands that are used as motion components,
may be included and is
always
considered part of the motion argument.
For example, the commands
"c2w
"
and
"2cw
"
are equivalent, and the region affected by the
c
command is two words of text.
In addition,
if the optional count prefix is specified for both the
vi
command and its motion component,
the effect is multiplicative and is considered part of the motion argument.
For example, the commands
"4cw
"
and
"2c2w
"
are equivalent, and the region affected by the
c
command is four words of text.
A positive number used as an optional argument to most commands,
either to give a size or a position (for display or movement commands),
or as a repeat count (for commands that modify text).
The count argument is always optional and defaults to 1 unless otherwise
noted in the command description.
When a
vi
command synopsis shows both a
[buffer]
and
[count]
,
they may be presented in any order.
Generally, in languages where it is applicable,
vi
recognizes two kinds of words.
First, a sequence of letters, digits and underscores,
delimited at both ends by:
characters other than letters, digits, or underscores,
the beginning or end of a line, and the beginning or end of the file.
Second, a sequence of characters other than letters, digits, underscores,
or whitespace characters, delimited at both ends by: a letter, digit,
underscore, or whitespace character,
the beginning or end of a line, and the beginning or end of the file.
For example, the characters
"!@#abc$%^
"
contain three words:
"!@#
",
"abc
"
and
"$%^
".
Groups of empty lines (or lines containing only whitespace characters) are treated as a single word.
A set of non-whitespace characters preceded and followed by whitespace
characters or the beginning or end of the file or line.
For example, the characters
"!@#abc$%^
"
contain one bigword:
"!@#abc$%^
".
Groups of empty lines (or lines containing only whitespace characters) are treated as a single bigword.
An area of text that begins with either the beginning of a file,
an empty line, or a section boundary, and continues until either
an empty line, section boundary, or the end of the file.
Groups of empty lines (or lines containing only whitespace characters)
are treated as a single paragraph.
Additional paragraph boundaries can be defined using the
paragraphs
option.
An area of text that starts with the beginning of the file or a line
whose first character is an open brace
"{
"
and continues until the next section or the end of the file.
Additional section boundaries can be defined using the
sections
option.
An area of text that begins with either the beginning of the file or the
first nonblank character following the previous sentence, paragraph, or
section boundary and continues until the end of the file or a period
".
"
exclamation point
"!
"
or question mark
"?
"
character,
followed by either an end-of-line or two whitespace characters.
Any number of closing parentheses
")
",
brackets
"]
",
double-quote
""
"
or single quote
"'
"
characters can appear between the period, exclamation point,
or question mark and the whitespace characters or end-of-line.
Groups of empty lines (or lines containing only whitespace characters) are treated as a single sentence.
The following section describes the commands available in the command mode of the vi editor. In each entry below, the tag line is a usage synopsis for the command character. In addition, the final line and column the cursor rests upon, and any options which affect the command are noted.
[count] |
Command |
Search forward
The <control-A> command is an absolute movement. The <control-A> command may be used as the motion component of other vi commands, in which case any text copied into a buffer is character oriented.
|
[count] |
Command |
Page backward
|
[count] |
Command |
Scroll forward
|
[count] |
Command |
Scroll forward
|
[count] |
Command |
Page forward
|
|
Command |
Display the file information. The information includes the current pathname, the current line, the number of total lines in the file, the current line as a percentage of the total lines in the file, if the file has been modified, was able to be locked, if the file's name has been changed, and if the edit session is read-only.
|
[count] |
Command |
[count] h | Command |
Move the cursor back
count characters in the current line.
It is an error if the cursor is on the first character in the line.
The <control-H> and h commands may be used as the motion component of other vi commands, in which case any text copied into a buffer is character oriented.
|
[count] |
Command |
[count] |
Command |
[count] j | Command |
Move the cursor down
count lines without changing the current column.
It is an error if the movement is past the end of the file.
The <control-J>, <control-N> and j commands may be used as the motion component of other vi commands, in which case any text copied into a buffer is line oriented.
|
|
Command |
|
Command |
Repaint the screen.
|
[count] |
Command |
[count] + | Command |
Move the cursor down
count lines to the first nonblank character of that line.
It is an error if the movement is past the end of the file.
The <control-M> and + commands may be used as the motion component of other vi commands, in which case any text copied into a buffer is line oriented.
|
[count] |
Command |
[count] k | Command |
Move the cursor up
count lines, without changing the current column.
It is an error if the movement is past the beginning of the file.
The <control-P> and k commands may be used as the motion component of other vi commands, in which case any text copied into a buffer is line oriented.
|
|
Command |
Return to the most recent tag context. The <control-T> command is an absolute movement.
|
[count] |
Command |
Scroll backward
|
|
Command |
Switch to the next lower screen in the window, or, to the first screen if there are no lower screens in the window.
|
[count] |
Command |
Scroll backward
|
|
Command |
Suspend the current editor session.
If the file has been modified since it was last completely written,
and the
|
|
Command |
Execute
ex
commands or cancel partial commands.
If an
ex
command is being entered (e.g.
/,
?,
:
or
!),
the command is executed.
If a partial command has been entered, e.g.
"
|
|
Command |
Push a tag reference onto the tag stack.
The tags files (see the
If the current file has been modified since it was last completely written, the command will fail. The <control-]> command is an absolute movement.
|
|
Command |
Switch to the most recently edited file.
If the file has been modified since it was last completely written,
and the
|
[count] |
Command |
[count] l | Command |
Move the cursor forward
count characters without changing the current line.
It is an error if the cursor is on the last character in the line.
The <space> and l commands may be used as the motion component of other vi commands, in which case any text copied into a buffer is character oriented. In addition, these commands may be used as the motion components of other commands when the cursor is on the last character in the line, without error.
|
[count] ! motion shell-argument(s) |
Command |
Replace text with results from a shell command.
Pass the lines specified by the
After the motion is entered,
vi
prompts for arguments to the shell command.
Within those arguments,
"
Vi
then executes the program named by the
The
!
command is permitted in an empty file.
If the file has been modified since it was last completely written, the ! command will warn you.
|
[count] # #|+|- | Command |
Increment or decrement the number referenced by the cursor.
If the trailing character is a
A leading
"
Octal and hexadecimal numbers, and the result of the operation, must fit
into an
"
|
[count] $ | Command |
Move the cursor to the end of a line.
If
It is not an error to use the
$
command when the cursor is on the last character in the line or
when the line is empty.
The $ command may be used as the motion component of other vi commands, in which case any text copied into a buffer is character oriented, unless the cursor is at, or before the first nonblank character in the line, in which case it is line oriented. It is not an error to use the $ command as a motion component when the cursor is on the last character in the line, although it is an error when the line is empty.
|
% | Command |
Move to the matching character.
The cursor moves to the parenthesis or curly brace which
matches
the parenthesis or curly brace found at the current cursor position
or which is the closest one to the right of the cursor on the line.
It is an error to execute the
%
command on a line without a parenthesis or curly brace.
Historically, any
The % command is an absolute movement. The % command may be used as the motion component of other vi commands, in which case any text copied into a buffer is character oriented, unless the starting point of the region is at or before the first nonblank character on its line, and the ending point is at or after the last nonblank character on its line, in which case it is line oriented.
|
& | Command |
Repeat the previous substitution command on the current line.
Historically, any
|
' |
Command |
` |
Command |
Return to a context marked by the character
<character> .
If
<character> is the
"' "
or
"` "
character, return to the previous context.
If
<character> is any other character,
return to the context marked by that character (see the
m
command for more information).
If the command is the
'
command, only the line value is restored,
and the cursor is placed on the first nonblank character of that line.
If the command is the
`
command, both the line and column values are restored.
It is an error if the context no longer exists because of
line deletion.
(Contexts follow lines that are moved, or which are deleted
and then restored.)
The ' and ` commands are both absolute movements. They may be used as a motion component for other vi commands. For the ' command, any text copied into a buffer is line oriented. For the ` command, any text copied into a buffer is character oriented, unless it both starts and stops at the first character in the line, in which case it is line oriented. In addition, when using the ` command as a motion component, commands which move backward and started at the first character in the line, or move forward and ended at the first character in the line, are corrected to the last character of the line preceding the starting and ending lines, respectively.
|
[count] ( | Command |
Back up
The ( command is an absolute movement. The ( command may be used as the motion component of other vi commands, in which case any text copied into a buffer is character oriented, unless the starting and stopping points of the region are the first character in the line, in which case it is line oriented. If it is line oriented, the starting point of the region is adjusted to be the end of the line immediately before the starting cursor position.
|
[count] ) | Command |
Move forward
The ) command is an absolute movement. The ) command may be used as the motion component of other vi commands, in which case any text copied into a buffer is character oriented, unless the starting point of the region is the first character in the line, in which case it is line oriented. In the latter case, if the stopping point of the region is also the first character in the line, it is adjusted to be the end of the line immediately before it.
|
[count] , | Command |
Reverse find character
The , command may be used as the motion component of other vi commands, in which case any text copied into a buffer is character oriented.
|
[count] - | Command |
Move to the first nonblank of the previous line,
It is an error if the movement is past the beginning of the file.
The - command may be used as the motion component of other vi commands, in which case any text copied into a buffer is line oriented.
|
[count] . | Command |
Repeat the last
vi
command that modified text.
The repeated command may be a command and motion component combination.
If
As a special case, if the . command is executed immediately after the u command, the change log is rolled forward or backward, depending on the action of the u command.
|
/RE |
Command |
/RE/ [ | Command |
?RE |
Command |
?RE? [ | Command |
N | Command |
n | Command |
Search forward or backward for a regular expression.
The commands beginning with a slash
"/ "
character are forward searches, the commands beginning with a
question mark
"? "
are backward searches.
Vi
prompts with the leading character on the last line of the screen
for a string.
It then searches forward or backward in the file for the next
occurrence of the string, which is interpreted as a Basic Regular
Expression.
The
/
and
?
commands are absolute movements.
They may be used as the motion components of other
vi
commands, in which case any text copied into a buffer is
character oriented, unless the search started and ended on
the first column of a line, in which case it is line oriented.
In addition, forward searches ending at the first character of a line,
and backward searches beginning at the first character in the line,
are corrected to begin or end at the last character of the previous line.
(Note, forward and backward searches can occur for both
/
and
?
commands, if the
If an offset from the matched line is specified (i.e. a trailing
"
The
N
command repeats the previous search, but in the reverse direction.
The
n
command repeats the previous search.
If either the
N
or
n
commands are used as motion components for the
!
command, you will not be prompted for the text of the bang command,
instead the previous bang command will be executed.
Missing RE's (e.g.
"
Searches may be interrupted using the
Multiple search patterns may be grouped together by delimiting
them with semicolons and zero or more whitespace characters, e.g.
It is also permissible to append a
z
command to the search strings, e.g.
|
0 | Command |
Move to the first character in the current line.
It is not an error to use the
0
command when the cursor is on the first character in the line,
The 0 command may be used as the motion component of other vi commands, in which case it is an error if the cursor is on the first character in the line, and any text copied into a buffer is character oriented.
|
: | Command |
Execute an
ex
command.
Vi
prompts for an
ex
command on the last line of the screen, using a colon
"
If the
ex
command writes to the screen,
vi
will prompt the user for a
When the
ex
command finishes, and the user is prompted to resume visual mode,
it is also possible to enter another
"
|
[count] ; | Command |
Repeat the last character find
The ; command may be used as the motion component of other vi commands, in which case any text copied into a buffer is character oriented.
|
[count] < motion | Command |
[count] > motion | Command |
Shift lines left or right.
Shift the number of lines in the region specified by the
count and
motion left (for the
<
command) or right (for the
>
command) by the number of columns specified by the
shiftwidth
option.
Only whitespace characters are deleted when shifting left.
Once the first character in the line no longer contains a whitespace
character, the command will succeed,
but the line will not be modified.
|
@@ buffer | Command |
Execute a named buffer.
Execute the named buffer as
vi
commands.
The buffer may include
ex
commands, too, but they must be expressed as a
:
command.
If the buffer is line oriented,
If the buffer name is
"
|
[count] A | Command |
Enter input mode, appending the text after the end of the line.
If
|
[count] B | Command |
Move backward
The B command may be used as the motion component of other vi commands, in which case any text copied into a buffer is character oriented.
|
[buffer] [count] C | Command |
Change text from the current position to the end-of-line.
If
|
[buffer] D | Command |
Delete text from the current position to the end-of-line.
It is not an error to execute the D command on an empty line.
|
[count] E | Command |
Move forward
The E command may be used as the motion component of other vi commands, in which case any text copied into a buffer is character oriented.
|
[count] F |
Command |
Search
The F command may be used as the motion component of other vi commands, in which case any text copied into a buffer is character oriented.
|
[count] G | Command |
Move to line
The G command is an absolute movement. The G command may be used as the motion component of other vi commands, in which case any text copied into a buffer is line oriented.
|
[count] H | Command |
Move to the screen line
The H command is an absolute movement. The H command may be used as the motion component of other vi commands, in which case any text copied into a buffer is line oriented.
|
[count] I | Command |
Enter input mode, inserting the text at the beginning of the line.
If
|
[count] J | Command |
Join lines.
If
If the current line ends with a whitespace character, all whitespace
is stripped from the next line.
Otherwise, if the next line starts with a open parenthesis
"
It is not an error to join lines past the end of the file, i.e. lines that do not exist.
|
[count] L | Command |
Move to the screen line
The L command is an absolute movement. The L command may be used as the motion component of other vi commands, in which case any text copied into a buffer is line oriented.
|
M | Command |
Move to the screen line in the middle of the screen.
The
M
command is an absolute movement.
The
M
command may be used as the motion component of other
vi
commands, in which case any text copied into a buffer is
line oriented.
Historically, any
|
[count] O | Command |
Enter input mode, appending text in a new line above the current line.
If
Historically, any
|
[buffer] P | Command |
Insert text from a buffer. Text from the buffer (the unnamed buffer by default) is inserted before the current column or, if the buffer is line oriented, before the current line.
|
Q | Command |
Exit vi (or visual) mode and switch to ex mode.
|
[count] R | Command |
Enter input mode, replacing the characters in the current line.
If
If the end of the current line is reached, no more characters are replaced and any further characters input are appended to the line.
|
[buffer] [count] S | Command |
Substitute
|
[count] T |
Command |
Search backward,
The T command may be used as the motion component of other vi commands, in which case any text copied into a buffer is character oriented.
|
U | Command |
Restore the current line to its state before the cursor last moved to it.
|
[count] W | Command |
Move forward
The W command may be used as the motion component of other vi commands, in which case any text copied into a buffer is character oriented.
|
[buffer] [count] X | Command |
Delete
|
[buffer] [count] Y | Command |
Copy (or
"yank")
|
ZZ | Command |
Write the file and exit
vi.
The file is only written if it has been modified since the last
complete write of the file to any file.
The ZZ command will exit the editor after writing the file, if there are no further files to edit. Entering two "quit" commands (i.e. wq, quit, xit or ZZ) in a row will override this check and the editor will exit, ignoring any files that have not yet been edited.
|
[count] [[ | Command |
Back up
The
[[
command is an absolute movement.
The
[[
command may be used as the motion component of other
vi
commands, in which case any text copied into a buffer is
character oriented, unless the starting position is column 0,
in which case it is line oriented.
It is an error if the movement is past the beginning of the file.
|
[count] ]] | Command |
Move forward
The
]]
command is an absolute movement.
The
]]
command may be used as the motion component of other
vi
commands, in which case any text copied into a buffer is
character oriented, unless the starting position is column 0,
in which case it is line oriented.
It is an error if the movement is past the end of the file.
|
^ | Command |
Move to first nonblank character on the current line.
The ^ command may be used as the motion component of other vi commands, in which case any text copied into a buffer is character oriented.
|
[count] _ | Command |
Move down
It is not an error to execute the _ command when the cursor is on the first character in the line.
|
[count] a | Command |
Enter input mode, appending the text after the cursor.
If
|
[count] b | Command |
Move backward
The b command may be used as the motion component of other vi commands, in which case any text copied into a buffer is character oriented.
|
[buffer] [count] c motion | Command |
Change the region of text specified by the
|
[buffer] [count] d motion | Command |
Delete the region of text specified by the
|
[count] e | Command |
Move forward
The e command may be used as the motion component of other vi commands, in which case any text copied into a buffer is character oriented.
|
[count] f |
Command |
Search forward,
The f command may be used as the motion component of other vi commands, in which case any text copied into a buffer is character oriented.
|
[count] i | Command |
Enter input mode, inserting the text before the cursor.
If
|
m |
Command |
Save the current context (line and column) as
Historically,
|
[count] o | Command |
Enter input mode, appending text in a new line under the current line.
If
Historically, any
|
[buffer] p | Command |
Append text from a buffer. Text from the buffer (the unnamed buffer by default) is appended after the current column or, if the buffer is line oriented, after the current line.
|
[count] r |
Command |
Replace characters.
The next
If
|
[buffer] [count] s | Command |
Substitute
|
[count] t |
Command |
Search forward,
The t command may be used as the motion component of other vi commands, in which case any text copied into a buffer is character oriented.
|
u | Command |
Undo the last change made to the file.
If repeated, the
u
command alternates between these two states, and is its own inverse.
When used after an insert that inserted text on more than one line,
the lines are saved in the numeric buffers.
The . command, when used immediately after the u command, causes the change log to be rolled forward or backward, depending on the action of the u command.
|
[count] w | Command |
Move forward
The w command may be used as the motion component of other vi commands, in which case any text copied into a buffer is character oriented.
|
[buffer] [count] x | Command |
Delete
|
[buffer] [count] y motion | Command |
Copy (or
"yank")
the text region specified by the
|
[count1] z [ | Command |
Redraw the screen with a window
The following
|
[count] @{ | Command |
Move backward
The { command is an absolute movement. The { command may be used as the motion component of other vi commands, in which case any text copied into a buffer is character oriented, unless the starting character is the first character on its line, in which case it is line oriented.
|
[count] | | Command |
Move to a specific
column
position on the current line.
The | command may be used as the motion component of other vi commands, in which case any text copied into a buffer is character oriented. It is an error to use the | command as a motion component and for the cursor not to move.
|
[count] @} | Command |
Move forward
The } command is an absolute movement. The } command may be used as the motion component of other vi commands, in which case any text copied into a buffer is character oriented, unless the starting character is at or before any nonblank characters in its line, in which case it is line oriented.
|
[count] ~ | Command |
Reverse the case of the next
Lowercase alphabetic characters are changed to uppercase,
and uppercase characters are changed to lowercase.
No other characters are affected.
Historically, the
~
command did not take an associated count, nor did it move past the
end of the current line.
As it had no associated motion it was difficult to change the case
of large blocks of text.
In
nvi,
if the cursor is on the last character of a line, and there are
more lines in the file, the cursor moves to the next line.
It is not an error to specify a count larger than the number of characters between the cursor and the end of the file.
|
[count] ~ motion | Command |
Reverse the case of the characters in a text region specified by the
Lowercase characters are changed to uppercase, and uppercase characters are changed to lowercase. No other characters are affected.
|
|
Command |
Interrupt the current operation.
Many of the potentially long-running
vi
commands may be interrupted using the terminal interrupt character.
These operations include searches, file reading and writing, filter
operations and map character expansion.
Interrupts are also enabled when running commands outside of
vi.
If the
Generally, if the
|
The following section describes the commands available in the text input mode of the vi editor.
Historically,
vi
implementations only permitted the characters inserted on the current
line to be erased.
In addition, only the
<control-D>
erase character and the
"0<control-D>
"
and
"^<control-D>
"
erase strings could erase autoindent characters.
(Autoindent characters include both the characters inserted automatically
at the beginning of an input line as well as characters inserted using the
<control-T>
command.)
This implementation permits erasure to continue past the beginning
of the current line, and back to where text input mode was entered.
In addition, autoindent characters may be erased using the standard
erase characters.
For the line and word erase characters, reaching the autoindent
characters forms a
"soft"
boundary, denoting the end of the current word or line erase.
Repeating the word or line erase key will erase the autoindent characters.
Historically,
vi
always used
<control-H>
and
<control-W>
as character and word erase characters, respectively, regardless of
the current terminal settings.
This implementation accepts, in addition to these two characters,
the current terminal characters for those operations.
|
Input |
If the first character of the input is a
|
|
Input |
If the previous character on the line was an autoindent character,
erase characters to move the cursor back to the column immediately
after the previous (1-based) column which is a multiple of the
Otherwise, if the
|
^ |
Input |
If the previous character on the line was an autoindent character, erase all of the autoindent characters on the line. In addition, the autoindent level is reset to 0. |
0 |
Input |
If the previous character on the line was an autoindent character, erase all of the autoindent characters on the line. The autoindent level is not altered. |
|
Input |
Insert sufficient
Historically,
vi
did not permit the
|
|
Input |
|
Input |
Erase the last character. |
|
Input |
Quote the next character.
The next character will not be mapped (see the
map
command for more information)
or interpreted specially.
A carat
" |
|
Input |
If on the colon command line, and the
|
|
Input |
Erase the current line. |
|
Input |
|
Input |
Erase the last word.
The definition of word is dependent on the
altwerase
and
ttywerase
options.
|
|
Input |
Insert a character with the specified hexadecimal value into the text. The value is delimited by any non-hexadecimal character or the input of the maximum number of characters that can be translated into a single character value. |
|
Input |
Interrupt text input mode, returning to command mode.
If the
|
Addressing in ex (and when ex commands are executed from vi ) relates to the current line. In general, the current line is the last line affected by a command. The exact effect on the current line is discussed under the description of each command. When the file contains no lines, the current line is zero.
Addresses are constructed by one or more of the following methods:
.
"
refers to the current line.
$
"
refers to the last line of the file.
N
",
where
N
is a positive number, refers to the N-th line of the file.
'<character>
"
or
"`<character>
"
refers to the line marked with the name
<character>
.
(See the
k
or
m
commands for more information on how to mark lines.)
/
"
is an address,
and it refers to the first line found by searching forward from the line
after
the current line toward the end of the file, and stopping at the
first line containing a string matching the RE.
(The trailing slash can be omitted at the end of the command line.)
If no RE is specified, i.e. the pattern is
"//
",
the last RE used in any command is used in the search.
If the
extended
option is set, the RE is handled as an extended RE, not a basic RE.
If the
wrapscan
option is set, the search wraps around to the beginning of the file
and continues up to and including the current line, so that the entire
file is searched.
The form
"e/
"
is accepted for historic reasons,
and is identical to
"//
".
?
"
addresses the first line found by searching backward from the line
preceding
the current line, toward the beginning of the file and stopping at the
first line containing a string matching the RE.
(The trailing question mark can be omitted at the end of a command line.)
If no RE is specified, i.e. the pattern is
"??
",
the last RE used in any command is used in the search.
If the
extended
option is set, the RE is handled as an extended RE, not a basic RE.
If the
wrapscan
option is set, the search wraps around from the beginning of the file to
the end of the file and continues up to and including the current line,
so that the entire file is searched.
The form
"e?
"
is accepted for historic reasons, and is identical to
"??
".
+
"
or a minus sign
"-
"
followed by a number is an offset address and refers to the address
plus (or minus) the indicated number of lines.
If the address is omitted, the addition or subtraction is done with
respect to the current line.
+
"
or
"-
"
followed by a number is an offset from the current line.
For example,
"-5
"
is the same as
".-5
".
+
"
or
"-
"
has 1 added to or subtracted from the address, respectively.
As a consequence of this rule and of the previous rule, the address
"-
"
refers to the line preceding the current line.
Moreover, trailing
"+
"
and
"-
"
characters have a cumulative effect.
For example,
"++-++
"
refers to the current line plus 3.
%
"
is equivalent to the address range
"1,$
".
Ex commands require zero, one, or two addresses. It is an error to specify an address to a command which requires zero addresses.
If the user provides more than the expected number of addresses to any
ex
command, the first addresses specified are discarded.
For example,
"1,2,3,5
"print
prints lines 3 through 5, because the
print
command only takes two addresses.
The addresses in a range are separated from each other by a comma
",
"
or a semicolon
";
".
In the latter case, the current line
".
"
is set to the first address, and only then is the second address calculated.
This feature can be used to determine the starting line for forward and
backward searches (see rules (5) and (6) above).
The second address of any two-address sequence corresponds to a line that
follows, in the file, the line corresponding to the first address.
The first address must be less than or equal to the second address.
The first address must be greater than or equal to the first line of the
file, and the last address must be less than or equal to the last line
of the file.
The following words have special meanings for ex commands.
The end-of-file character is used to scroll the screen in the
ex
editor.
This character is normally
<control-D>
.
However, whatever character is set for the current terminal is supported
as well as
<control-D>
.
A single-line address, given in any of the forms described in the
section entitled
"Ex Addressing" .
The default for
line
is the current line.
A line, or a pair of line addresses, separated by a comma or semicolon.
(See the section entitled
"Ex Addressing"
for more information.)
The default for range is the current line
only,
i.e.
".,.
".
A percent sign
"%
"
stands for the range
"1,$
".
The starting address must be less than, or equal to, the ending address.
A positive integer, specifying the number of lines to be affected by
the command; the default is 1.
Generally, a count past the end-of-file may be specified, e.g. the
command
"p 3000
"
in a 10 line file is acceptable, and will print from the current line
through the last line in the file.
One or more of the characters
"#",
"p",
and
"l".
When a command that accepts these flags completes, the addressed line(s)
are written out as if by the corresponding
#,
l
or
p
commands.
In addition, any number of
"+
"
or
"-
"
characters can be specified before, after, or during the flags, in which
case the line written is not necessarily the one affected by the command,
but rather the line addressed by the offset address specified.
The default for
flags
is none.
A pattern used to derive a pathname; the default is the current file.
File names are subjected to normal
sh
(1)
word expansions.
Anywhere a file name is specified, it is also possible to use
the special string
"/tmp
".
This will be replaced with a temporary file name which can be used
for temporary work, e.g.
":e /tmp
"
creates and edits a new file.
If both a count and a range are specified for commands that use either,
the starting line for the command is the
last
line addressed by the range, and
count
- 1
subsequent lines are affected by the command, e.g. the command
"2,3p4
"
prints out lines 3, 4, 5 and 6.
When only a line or range is specified, with no command, the implied command is either a list, number or print command. The command used is the most recent of the three commands to have been used (including any use as a flag). If none of these commands have been used before, the print command is the implied command. When no range or count is specified and the command line is a blank line, the current line is incremented by 1 and then the current line is displayed.
Zero or more whitespace characters may precede or follow the addresses, count, flags, or command name. Any object following a command name (such as buffer, file, etc.), that begins with an alphabetic character, should be separated from the command name by at least one whitespace character.
Any character, including
<carriage-return>
,
"%
"
and
"#
"
retain their literal value when preceded by a backslash.
The following section describes the commands available in the ex editor. In each entry below, the tag line is a usage synopsis for the command.
Each command can be entered as the abbreviation
(those characters in the synopsis command word preceding the
"["
character),
the full command (all characters shown for the command word,
omitting the
"["
and
"]"
characters),
or any leading subset of the full command down to the abbreviation.
For example, the args command (shown as
"ar[gs]
"
in the synopsis)
can be entered as
"ar
",
"arg
"
or
"args
".
Each ex command described below notes the new current line after it is executed, as well as any options that affect the command.
" | Command |
A comment.
Command lines beginning with the double-quote character
" |
|
Command |
|
Command |
Scroll the screen.
Write the next N lines, where N is the value of the
Historically, the
eof
command ignored any preceding count, and the
|
! argument(s) | Command |
[range]! argument(s) | Command |
Execute a shell command, or filter lines through a shell command.
In the first synopsis, the remainder of the line after the
"! "
character is passed to the program named by the
shell
option, as a single argument.
Within the rest of the line,
"
Ex
then executes the program named by the
The
!
command is permitted in an empty file.
If the file has been modified since it was last completely written,
the
!
command will warn you.
A single
"
In the second form of the
!
command, the remainder of the line after the
"
|
[range] # [ | Command |
[range] nu[mber] [ | Command |
Display the selected lines, each preceded with its line number.
The line number format is "%6d", followed by two spaces.
|
@@ buffer | Command |
* buffer | Command |
Execute a buffer.
Each line in the named buffer is executed as an
ex
command.
If no buffer is specified, or if the specified buffer is
"@ "
or
"* ",
the last buffer executed is used.
|
[range] <[< ...] [ | Command |
Shift lines left or right.
The specified lines are shifted to the left (for the
<
command) or right (for the
>
command), by the number of columns specified by the
If the command character < or > is repeated more than once, the command is repeated once for each additional command character.
|
[line] = [ | Command |
Display the line number of
|
[range] >[> ...] [ | Command |
Shift right.
The specified lines are shifted to the right by the number of columns
specified by the
If the command character
"
|
ab[brev] lhs rhs | Command |
Add an abbreviation to the current abbreviation list.
When inserting text in
vi,
each time a non-word character is entered after a word character,
a set of characters ending at the word character are checked for
a match with
For example, the abbreviations:
To keep the abbreviation expansion from happening,
the character immediately following the
The replacement
|
[line] a[ppend][!] | Command |
The input text is appended to the specified line.
If line 0 is specified, the text is inserted at the beginning of the file.
Set to the last line input.
If no lines are input, then set to
|
ar[gs] | Command |
Display the argument list.
The current argument is displayed inside of
"
|
bg | Command |
Vi mode only. Background the current screen. The screen is unchanged, but is no longer accessible and disappears from the display. Use the fg command to bring the screen back to the display foreground.
|
[range] c[hange][!] [ | Command |
Replace the lines with input text.
Following the command name with a
"
|
chd[ir][!] [ | Command |
cd[!] [ | Command |
Change the current working directory.
The
directory argument is subjected to
sh (1)
word expansions.
When invoked with no directory argument and the
HOME environment variable is set, the directory named by the
HOME environment variable becomes the new current directory.
Otherwise, the new current directory becomes the directory returned
by the
getpwent (3)
routine.
The
chdir
command will fail if the file has been modified since the last complete
write of the file.
You can override this check by appending a
"
|
[range] co[py] line [flags] | Command |
[range] t line [flags] | Command |
Copy the specified lines (range) after the destination line.
Line 0 may be specified to insert the lines at the beginning of
the file.
|
cs[cope] command [args] | Command |
Execute a cscope command. For more information, see the section of the reference manual entitled "Tags, Tag Stacks, and Cscope" . |
[range] d[elete] [ | Command |
Delete the lines from the file.
The deleted text is saved in the specified buffer, or, if no buffer
is specified, in the unnamed buffer.
If the command name is followed by a letter that could be interpreted
as either a buffer name or a flag value (because neither a
|
di[splay] b[uffers] | c[onnections] | s[creens] | t[ags] | Command |
Display buffers, cscope connections, screens or tags. The display command takes one of three additional arguments, which are as follows:
|
e[dit][!] [ | Command |
ex[!] [ | Command |
vs[plit][!] [ | Command |
Edit a different file.
If the current buffer has been modified since the last complete write,
the command will fail.
You can override this by appending a
"! "
character to the command name.
If the
"
Capitalizing the first letter of the command, i.e., Edit or Ex, while in vi mode, will edit the file in a new screen. In this case, any modifications to the current file are ignored. vsplit is similar, but the screen will be split vertically to produce the new screen, rather than horizontally.
|
exu[sage] [ | Command |
Display usage for an
ex
command.
If
|
f[ile] [ | Command |
Display and optionally change the file name. If a file name is specified, the current pathname is changed to the specified name. The current pathname, the number of lines, and the current position in the file are displayed.
|
fg [ | Command |
Vi
mode only.
Foreground the specified screen.
If the argument name doesn't exactly match the name of a file displayed
by a background screen,
it is compared against the last component of each of the file names.
If no background screen is specified,
the first background screen is foregrounded.
By default, foregrounding causes the current screen to be swapped with the backgrounded screen. Capitalizing the first letter of the command, i.e. Fg, will foreground the backgrounded screen in a new screen instead of swapping it with the current screen.
|
[range] g[lobal] /pattern/ [commands] | Command |
[range] v /pattern/ [commands] | Command |
Apply commands to lines matching (or not matching) a pattern.
The lines within the given range that match
"g[lobal] ",
or do not match
"v "
the given pattern are selected.
Then, the specified
ex
command(s) are executed with the current line
". "
set to each selected line.
If no range is specified, the entire file is searched for matching,
or not matching, lines.
Multiple commands can be specified, one per line, by escaping each
For the
append,
change
and
insert
commands, the input text must be part of the global command line.
In this case, the terminating period can be omitted if it ends the commands.
The
visual
command may also be specified as one of the
ex
commands.
In this mode, input is taken from the terminal.
Entering a
Q
command in
vi
mode causes the next line matching the pattern to be selected and
vi
to be reentered, until the list is exhausted.
The
global,
v
and
undo
commands cannot be used as part of these commands.
The editor options
|
he[lp] | Command |
Display a help message.
|
[line] i[nsert][!] | Command |
The input text is inserted before the specified line.
Following the command name with a
"
|
[range] j[oin][!] [ | Command |
Join lines of text together.
A
If the current line ends with a whitespace character, all whitespace
is stripped from the next line.
Otherwise, if the next line starts with a open parenthesis
"
Appending a
"
|
[range] l[ist] [ | Command |
Display the lines unambiguously.
Tabs are displayed as
"
|
map[!] [ | Command |
Define or display maps (for
vi
only).
If
"
Otherwise, when the
"
Whitespace characters require escaping with a
Normally, keys in the
To exit an infinitely looping map, use the terminal
|
[line] ma[rk] |
Command |
[line] k |
Command |
Mark the line with the mark
<character> .
The expressions
"'<character> "
and
"`<character> "
can then be used as an address in any command that uses one.
|
[range] m[ove] line | Command |
Move the specified lines after the target line. A target line of 0 places the lines at the beginning of the file.
|
mk[exrc][!] file | Command |
Write the abbreviations, editor options and maps to the specified
file.
Information is written in a form which can later be read back in
using the
ex
source
command.
If
|
n[ext][!] [ | Command |
Edit the next file from the argument list.
The
next
command will fail if the file has been modified since the last complete
write.
This check can be overridden by appending the
"
Capitalizing the first letter of the command, i.e. Next, while in vi mode, will set the argument list and edit the file in a new screen. In this case, any modifications to the current file are ignored.
|
[line] o[pen] /pattern/ [flags] | Command |
Enter open mode.
Open mode is the same as being in
vi,
but with a one-line window.
All the standard
vi
commands are available.
If a match is found for the optional RE argument,
the cursor is set to the start of the matching pattern.
This command is not yet implemented.
|
pre[serve] | Command |
Save the file in a form that can later be recovered using the ex -r option. When the file is preserved, an email message is sent to the user.
|
prev[ious][!] | Command |
Edit the previous file from the argument list.
The
previous
command will fail if the file has been modified since the last complete
write.
This check can be overridden by appending the
"
Capitalizing the first letter of the command, i.e. Previous, while in vi mode, will edit the file in a new screen. In this case, any modifications to the current file are ignored.
|
[range] p[rint] [ | Command |
Display the specified lines.
|
[line] pu[t] [ | Command |
Append buffer contents to the current line. If a buffer is specified, its contents are appended to the line, otherwise, the contents of the unnamed buffer are used.
|
q[uit][!] | Command |
End the editing session.
If the file has been modified since the last complete write, the
quit
command will fail.
This check may be overridden by appending a
"
If there are more files to edit, the
quit
command will fail.
Appending a
"
|
[line] r[ead][!] [ | Command |
Read a file.
A copy of the specified file is appended to the line.
If
If
|
rec[over] file | Command |
Recover
|
res[ize] [ | Command |
Vi
mode only.
Grow or shrink the current screen.
If
|
rew[ind][!] | Command |
Rewind the argument list.
If the current file has been modified since the last complete write,
the
rewind
command will fail.
This check may be overridden by appending the
"
Otherwise, the current file is set to the first file in the argument list.
|
se[t] [ | Command |
Display or set editor options.
When no arguments are specified, the editor option
Specifying an option name followed by the character
"
|
sh[ell] | Command |
Run the shell program.
The program named by the
|
so[urce] file | Command |
Read and execute ex commands from a file. Source commands may be nested.
|
[range] s[ubstitute] [ | Command |
[range] & [ | Command |
[range] ~ [ | Command |
Make substitutions.
Replace the first instance of
pattern with the string
replace on the specified line(s).
If the
"/pattern/repl/ "
argument is not specified, the
"/pattern/repl/ "
from the previous
substitute
command is used.
Any character other than an alphabetic, numeric, <blank> or backslash
character may be used as the delimiter.
If
The
&
version of the command is the same as not specifying a pattern
or replacement string to the
substitute
command, and the
"
The
~
version of the command is the same as
&
and
s,
except that the search pattern used is the last RE used in
any
command, not necessarily the one used in the last
substitute
command.
For example, in the sequence s/red/blue/ /green ~the " ~ "
is equivalent to
"s/green/blue/ ".
The substitute command may be interrupted, using the terminal interrupt character. All substitutions completed before the interrupt are retained.
|
su[spend][!] | Command |
st[op][!] | Command |
|
Comamnd |
Suspend the edit session.
Appending a
"! "
character to these commands turns off the
autowrite
option for the command.
|
ta[g][!] tagstring | Command |
Edit the file containing the specified tag.
If the tag is in a different file, then the new file is edited.
If the current file has been modified since the last complete write,
the
tag
command will fail.
This check can be overridden by appending the
"
The
tag
command searches for
Capitalizing the first letter of the command, i.e. Tag, while in vi mode, will edit the file in a new screen. In this case, any modifications to the current file are ignored.
|
tagn[ext][!] | Command |
Edit the file containing the next context for the current tag.
If the context is in a different file, then the new file is edited.
If the current file has been modified since the last complete write,
the
tagnext
command will fail.
This check can be overridden by appending the
"
Capitalizing the first letter of the command, i.e. Tagnext, while in vi mode, will edit the file in a new screen. In this case, any modifications to the current file are ignored.
|
tagp[op][!] [ | Command |
Pop to the specified tag in the tags stack.
If neither
If the file has been modified since the last complete write, the
tagpop
command will fail.
This check may be overridden by appending a
"
|
tagp[rev][!] | Command |
Edit the file containing the previous context for the current tag.
If the context is in a different file, then the new file is edited.
If the current file has been modified since the last complete write,
the
tagprev
command will fail.
This check can be overridden by appending the
"
Capitalizing the first letter of the command, i.e. Tagprev, while in vi mode, will edit the file in a new screen. In this case, any modifications to the current file are ignored.
|
tagt[op][!] | Command |
Pop to the least recent tag on the tags stack, clearing the tags stack.
If the file has been modified since the last complete write, the
tagtop
command will fail.
This check may be overridden by appending a
"
|
una[bbrev] lhs | Command |
Delete an abbreviation.
Delete
|
u[ndo] | Command |
Undo the last change made to the file. Changes made by global, v, visual and map sequences are considered a single command. If repeated, the u command alternates between these two states, and is its own inverse.
|
unm[ap][!] lhs | Command |
Unmap a mapped string.
Delete the command mode map definition for
|
ve[rsion] | Command |
Display the version of the ex/vi editor. |
[line] vi[sual] [ | Command |
Ex
mode only.
Enter
vi.
The
|
vi[sual][!] [ | Command |
Vi
mode only.
Edit a new file.
Identical to the
"
Capitalizing the first letter of the command, i.e. Visual, will edit the file in a new screen. In this case, any modifications to the current file are ignored. |
viu[sage] [ | Command |
Display usage for a
vi
command.
If
|
[range] w[rite][!] [ | Command |
[range] w[rite] [ | Command |
[range] wn[!] [ | Command |
[range] wq[!] [ | Command |
Write the file.
The specified lines (the entire file, if no range is given) is written
to
file .
If
file is not specified, the current pathname is used.
If
file is specified, and it exists, or if the current pathname was set using the
file
command, and the file already exists, these commands will fail.
Appending a
"! "
character to the command name will override this check and the write
will be attempted, regardless.
Specifying the optional
"
If the file is preceded by a
"
The
wq
version of the write command will exit the editor after writing the file,
if there are no further files to edit.
Appending a
"
The wn version of the write command will move to the next file after writing the file, unless the write fails.
|
[range] x[it][!] [ | Command |
Write the file if it has been modified.
The specified lines are written to
The
xit
command will exit the editor after writing the file,
if there are no further files to edit.
Appending a
"
|
[range] ya[nk] [ | Command |
Copy the specified lines to a buffer. If no buffer is specified, the unnamed buffer is used.
|
[line] z [ | Command |
Adjust the window.
If no
|
There are a large number of options that may be set (or unset) to change the editor's behavior. This section describes the options, their abbreviations and their default values.
In each entry below, the first part of the tag line is the full name of the option, followed by any equivalent abbreviations. (Regardless of the abbreviations, it is only necessary to use the minimum number of characters necessary to distinguish an abbreviation from all other commands for it to be accepted, in nex/nvi. Historically, only the full name and the official abbreviations were accepted by ex/vi. Using full names in your startup files and environmental variables will probably make them more portable.) The part in square brackets is the default value of the option. Most of the options are boolean, i.e. they are either on or off, and do not have an associated value.
Options apply to both ex and vi modes, unless otherwise specified.
With a few exceptions,
all options are settable per screen, i.e. the
tags
option can be set differently in each screen.
The exceptions are the
columns
,
lines
,
secure
and
term
options.
Changing these options modifies the respective information for all screens.
For information on modifying the options or to display the options and their current values, see the "set" command in the section entitled "Ex Commands" .
Vi only. Change how vi does word erase during text input. When this option is set, text is broken up into three classes: alphabetic, numeric and underscore characters, other nonblank characters, and blank characters. Changing from one class to another marks the end of a word. In addition, the class of the first character erased is ignored (which is exactly what you want when erasing pathname components).
If this option is set, whenever you create a new line (using the
vi
A,
a,
C,
c,
I,
i,
O,
o,
R,
r,
S,
and
s
commands, or the
ex
append,
change,
and
insert
commands) the new line is automatically indented to align the cursor with
the first nonblank character of the line from which you created it.
Lines are indented using tab characters to the extent possible (based on
the value of the
tabstop
option) and then using space characters as necessary.
For commands inserting text into the middle of a line, any blank characters
to the right of the cursor are discarded, and the first nonblank character
to the right of the cursor is aligned as described above.
The indent characters are themselves somewhat special.
If you do not enter more characters on the new line before moving to
another line, or entering
<escape>
,
the indent character will be deleted and the line will be empty.
For example, if you enter
<carriage-return>
twice in succession,
the line created by the first
<carriage-return>
will not have any characters in it,
regardless of the indentation of the previous or subsequent line.
Indent characters also require that you enter additional erase characters
to delete them.
For example,
if you have an indented line, containing only blanks, the first
<word-erase>
character you enter will erase up to end of the indent characters,
and the second will erase back to the beginning of the line.
(Historically, only the
<control-D>
key would erase the indent characters.
Both the
<control-D>
key and the usual erase keys work in
nvi.)
In addition, if the cursor is positioned at the end of the indent
characters, the keys
"0<control-D>
"
will erase all of the indent characters for the current line,
resetting the indentation level to 0.
Similarly, the keys
"^<control-D>
"
will erase all of the indent characters for the current line,
leaving the indentation level for future created lines unaffected.
Finally, if the
autoindent
option is set, the
S
and
cc
commands change from the first nonblank of the line to the end of the
line, instead of from the beginning of the line to the end of the line.
Ex only. Cause the current line to be automatically displayed after the ex commands <, >, copy, delete, join, move, put, t, Undo, and undo. This automatic display is suppressed during global and v commands, and for any command where optional flags are used to explicitly display the line.
If this option is set, the
vi
!,
^^,
^]
and
<control-Z>
commands, and the
ex
edit,
next,
rewind,
stop,
suspend,
tag,
tagpop,
and
tagtop
commands automatically write the current file back to the current file name
if it has been modified since it was last written.
If the write fails, the command fails and goes no further.
Appending the optional force flag character
"!
"
to the
ex
commands
next,
rewind,
stop,
suspend,
tag,
tagpop,
and
tagtop
stops the automatic write from being attempted.
(Historically, the
next
command ignored the optional force flag.)
Note, the
ex
commands
edit,
quit,
shell,
and
xit
are
not
affected by the
autowrite
option.
The
autowrite
option is ignored if the file is considered read-only for any reason.
If this option is set, it specifies a pathname used as a backup file,
and, whenever a file is written, the file's current contents are copied
to it.
The pathname is
"#
",
"%
"
and
"!
"
expanded.
If the first character of the pathname is
"N
",
a version number is appended to the pathname (and the
"N
"
character is then discarded).
Version numbers are always incremented, and each backup file will have
a version number one greater than the highest version number currently
found in the directory.
Backup files must be regular files, owned by the real user ID of the user running the editor, and not accessible by any other user.
If this option is set, all control characters that are not currently being
specially interpreted, other than
<tab>
,
<newline>
,
and
<form-feed>
,
are
discarded from commands read in by
ex
from command files, and from input text entered to
vi
(either into the file or to the colon command line).
Text files read by
ex/vi
are
not
affected by the
beautify
option.
This option is used to specify a colon separated list of directories
which are used as path prefixes for any relative path names used as
arguments for the
cd
command.
The value of this option defaults to the value of the environmental
variable
CDPATH
if it is set, otherwise to the current directory.
For compatibility with the POSIX 1003.2 shell, the
cd
command does
not
check the current directory as a path prefix for relative path names
unless it is explicitly specified.
It may be so specified by entering an empty string or a
".
"
character into the
CDPATH
variable or the option value.
This option adds the ability to edit the colon command-line history.
This option is set to a string.
Whenever the first character of that string is entered on the colon
command line,
you will enter a normal editing window on the collected commands that
you've entered on the
vi
colon command-line.
You may then modify and/or execute the commands.
All normal text editing is available,
except that you cannot use
<control-W>
to switch to an alternate screen.
Entering a
<carriage-return>
will execute the current line of the screen window as an ex command in
the context of the screen from which you created the colon command-line
screen,
and you will then return to that screen.
Because of
vi's
parsing rules, it can be difficult to set the colon command-line edit
character to the
<escape>
character.
To set it to
<escape>
,
use
"set cedit=<literal-next><escape>
".
If the
cedit
edit option is set to the same character as the
filec
edit option,
vi
will perform colon command-line editing if the character is entered as
the first character of the line,
otherwise,
vi
will perform file name expansion.
The number of columns in the screen.
Setting this option causes
ex/vi
to set (or reset) the environmental variable
COLUMNS
.
See the section entitled
"Sizing the Screen"
more information.
Vi
only.
If the first non-empty line of the file begins with the string
"#
",
"/*
"
or
"//
",
this option causes
vi
to skip to the end of that shell, C or C++ comment (probably a
terribly boring legal notice) before displaying the file.
The directory where temporary files are created.
The environmental variable
TMPDIR
is used as the default value if it exists, otherwise
/tmp
is used.
Remember the values of the "c" and "g" suffixes to the substitute commands, instead of initializing them as unset for each new command. Specifying pattern and replacement strings to the substitute command unsets the "c" and "g" suffixes as well.
The 10th's of a second
ex/vi
waits for a subsequent key to complete an
<escape>
key mapping.
Ex only. Ex error messages are normally presented in inverse video. If that is not possible for the terminal, setting this option causes error messages to be announced by ringing the terminal bell.
If this option is turned on in the EXINIT environment variables, or the system or $HOME startup files, the local startup files are read, unless they are the same as the system or $HOME startup files or fail to pass the standard permission checks. See the section entitled "Startup Information" for more information.
This option causes all regular expressions to be treated as POSIX
1003.2 Extended Regular Expressions (which are similar to historic
egrep
(1)
style expressions).
This option adds the ability to do shell expansion when entering input
on the colon command line.
This option is set to a string.
Whenever the first character of that string is entered on the colon
command line,
the <blank> delimited string immediately before the cursor is expanded
as if it were followed by a
*
character, and file name expansion for the
ex
edit command was done.
If no match is found, the screen is flashed and text input resumed.
If a single match results, that match replaces the expanded text.
In addition, if the single match is for a directory, a
/
character is appended and file completion is repeated.
If more than a single match results,
any unique prefix shared by the matches replaces the expanded text,
the matches are displayed,
and text input resumed.
Because of
vi's
parsing rules, it can be difficult to set the path completion character
to two command values,
<escape>
and
<tab>
.
To set it to
<escape>
,
use
"set filec=<literal-next><escape>
".
To set it to
<tab>
,
use
"set filec=e<tab>
".
If the
cedit
edit option is set to the same character as the
filec
edit option,
vi
will perform colon command-line editing if the character is entered as
the first character of the line,
otherwise,
vi
will perform file name expansion.
This option causes the screen to flash instead of beeping the keyboard, on error, if the terminal has the capability.
This option defines the spacing between hardware tab settings, i.e.
the tab expansion done by the operating system and/or the terminal
itself.
As
nex/nvi
never writes
<tab>
characters to the terminal, unlike historic versions of
ex/vi,
this option does not currently have any affect.
The
iclower
edit option makes all Regular Expressions case-insensitive,
as long as an upper-case letter does not appear in the search string.
This option causes regular expressions, both in ex commands and in searches, to be evaluated in a case-insensitive manner.
The 10th's of a second ex/vi waits for a subsequent key to complete a key mapping.
Vi only. This option causes the screen to be scrolled left-right to view lines longer than the screen, instead of the traditional vi screen interface which folds long lines at the right-hand margin of the terminal.
Vi
only.
The number of lines in the screen.
Setting this option causes
ex/vi
to set (or reset) the environmental variable
LINES
.
See the section entitled
"Sizing the Screen"
for more information.
Vi
only.
This option changes the behavior of the
vi
(,
),
{,
},
[[
and
]]
commands to match the Lisp language.
Also, the
autoindent
option's behavior is changed to be appropriate for Lisp.
This option is not yet implemented.
This option causes lines to be displayed in an unambiguous fashion.
Specifically, tabs are displayed as control characters, i.e.
"^I
",
and the ends of lines are marked with a
"$
"
character.
This option causes the editor to attempt to get an exclusive lock on
any file being edited, read or written.
Reading or writing a file that cannot be locked produces a warning
message, but no other effect.
Editing a file that cannot be locked results in a read only edit session,
as if the
readonly
edit option were set.
This option is on by default.
Turning the
magic
option off causes all regular expression characters except for
"^
"
and
"$
",
to be treated as ordinary characters.
To re-enable characters individually, when the
magic
option is off,
precede them with a backslash
"e
"
character.
See the section entitled
"Regular Expressions and Replacement Strings"
for more information.
Vi
only.
The 10th's of a second
vi
pauses on the matching character when the
showmatch
option is set.
This option allows other users to contact you using the
talk
(1)
and
write
(1)
utilities, while you are editing.
Ex/vi
does not turn message on, i.e. if messages were turned off when the
editor was invoked, they will stay turned off.
This option only permits you to disallow messages for the edit session.
See the
mesg
(1)
utility for more information.
This option selects a message catalog to be used to display error and
informational messages in a specified language.
If the value of this option ends with a '/', it is treated as the name
of a directory that contains a message catalog
"vi_XXXX
",
where
"XXXX
"
is the value of the
LANG
environmental variable, if it's set, or the value of the
LC_MESSAGES
environmental variable if it's not.
If neither of those environmental variables are set,
or if the option doesn't end in a '/',
the option is treated as the full path name of the message catalog to use.
If any messages are missing from the catalog,
the backup text (English) is used instead.
See the distribution file
catalog/README
for additional information on building and installing message catalogs.
If the
modelines
option is set,
ex/vi
has historically scanned the first and last five lines of each file as
it is read for editing, looking for any
ex
commands that have been placed in those lines.
After the startup information has been processed, and before the user
starts editing the file, any commands embedded in the file are executed.
Commands were recognized by the letters
"e"
or
"v"
followed by
"x"
or
"i",
at the beginning of a line or following a tab or space character,
and followed by a
":",
an
ex
command, and another
":".
This option is a security problem of immense proportions,
and should not be used under any circumstances.
This option will never be implemented.
Characters that are never handled as printable characters.
By default, the C library function
isprint
(3)
is used to determine if a character is printable or not.
This edit option overrides that decision.
Precede each line displayed with its current line number.
Display unknown characters as octal numbers
""e###"
",
instead of the default
hexadecimal
""ex##"
".
Ex only. If this option is not set, the open and visual commands are disallowed.
Vi
only.
Throughput of text is expedited by setting the terminal not to do automatic
carriage returns when printing more than one (logical) line of output,
greatly speeding output on terminals without addressable cursors when text
with leading white space is printed.
This option is not yet implemented.
Vi
only.
Define additional paragraph boundaries for the
{
and
}
commands.
The value of this option must be a character string consisting
of zero or more character pairs.
In the text to be edited, the character string
<newline>.<char-pair>
,
(where
<char-pair>
is one of the character pairs in the option's value)
defines a paragraph boundary.
For example, if the option were set to
LaA<space>##
,
then all of the following additional paragraph boundaries would be
recognized:
<newline>.La <newline>.A<space> <newline>.##
The path option can be used to specify a <colon>-separated list of
paths, similar to the
PATH
environment variable in the shells.
If this option is set,
the name of the file to be edited is not an absolute pathname,
the first component of the filename is not
".
"
or
"..
",
and the file to be edited doesn't exist in the current directory,
the elements of the
path
option are sequentially searched for a file of the specified name.
If such a file is found, it is edited.
Characters that are always handled as printable characters.
By default, the C library function
isprint
(3)
is used to determine if a character is printable or not.
This edit option overrides that decision.
Ex
only.
This option causes
ex
to prompt for command input with a
":
"
character; when it is not set, no prompt is displayed.
This option causes a force flag to be required to attempt to write the file.
Setting this option is equivalent to using the
-R
command line option,
or executing the
vi
program using the name
view.
The
readonly
edit option is not usually persistent, like other edit options.
If the
-R
command line option is set,
vi
is executed as
view,
or the
readonly
edit option is explicitly set,
all files edited in the screen will be marked readonly,
and the force flag will be required to write them.
However, if none of these conditions are true,
or the
readonly
edit option is explicitly unset,
then the
readonly
edit option will toggle based on the write permissions of the file currently
being edited as of when it is loaded into the edit buffer.
In other words, the
readonly
edit option will be set if the current file lacks write permissions,
and will not be set if the user has write permissions for the file.
The directory where recovery files are stored.
If you change the value of
recdir
,
be careful to choose a directory whose contents are not regularly
deleted.
Bad choices include directories in memory based filesystems,
or
/tmp
,
on most systems,
as their contents are removed when the machine is rebooted.
Public directories like
/usr/tmp
and
/var/tmp
are usually safe, although some sites periodically prune old files
from them.
There is no requirement that you use a public directory,
e.g. a sub-directory of your home directory will work fine.
Finally, if you change the value of
recdir
,
you must modify the recovery script to operate in your chosen recovery
area.
See the section entitled "Recovery" for further information.
Vi
only.
The editor simulates (using great amounts of output), an intelligent
terminal on a dumb terminal (e.g. during insertions in
vi
the characters to the right of the cursor are refreshed as each input
character is typed).
This option is not yet implemented.
If this option is set,
it is possible to define macros in terms of other macros.
Otherwise, each key is only remapped up to one time.
For example, if
"A
"
is mapped to
"B
",
and
"B
"
is mapped to
"C
",
The keystroke
"A
"
will be mapped to
"C
"
if the
remap
option is set, and to
"B
"
if it is not set.
Set the threshold of the number of lines that need to be changed or yanked before a message will be displayed to the user. For everything but the yank command, the value is the largest value about which the editor is silent, i.e. by default, 6 lines must be deleted before the user is notified. However, if the number of lines yanked is greater than or equal to the set value, it is reported to the user.
Vi only. Display a row/column ruler on the colon command line.
Set the number of lines scrolled by the
ex
<control-D>
and
<end-of-file>
commands.
Historically, the ex z command, when specified without a count, used two times the size of the scroll value; the POSIX 1003.2 standard specified the window size, which is a better choice.
The
searchincr
edit option makes the search commands
/
and
?
incremental, i.e. the screen is updated and the cursor moves to the matching
text as the search pattern is entered.
If the search pattern is not found,
the screen is beeped and the cursor remains on the colon-command line.
Erasing characters from the search pattern backs the cursor up to the
previous matching text.
Vi
only.
Define additional section boundaries for the
[[
and
]]
commands.
The
sections
option should be set to a character string consisting of zero or
more character pairs.
In the text to be edited, the character string
<newline>.<char-pair>
,
(where
<char-pair>
is one of the character pairs in the option's value),
defines a section boundary in the same manner that
paragraphs
option boundaries are defined.
The
secure
edit option turns off all access to external programs.
This means that the versions of the
read
and
write
commands that filter text through other programs,
the
vi
!
and
<control-Z>
commands,
the
ex
!,
script,
shell,
stop
and
suspend
commands and file name expansion will not be permitted.
Once set,
the
secure
edit option may not be unset.
Select the shell used by the editor. The specified path is the pathname of the shell invoked by the vi ! shell escape command and by the ex shell command. This program is also used to resolve any shell meta-characters in ex commands.
The set of characters that
ex
checks for when doing file name expansion.
If any of the specified characters are found in the file name arguments
to the
ex
commands,
the arguments are expanded using the program defined by the
shell
option.
The default set of characters is a union of meta characters
from the Version 7 and the Berkeley C shell.
Set the autoindent and shift command indentation width.
This width is used by the
autoindent
option and by the
<,
>,
and
shift
commands.
Vi
only.
This option causes
vi,
when a
"}
"
or
")
"
is entered, to briefly move the cursor the matching
"{
"
or
"(
".
See the
matchtime
option for more information.
Vi only. This option causes vi to display a string identifying the current editor mode on the colon command line. The string is preceded by an asterisk ("*") if the file has been modified since it was last completely written,
Vi
only.
Sets the number of columns that are shifted to the left or right,
when
vi
is doing left-right scrolling and the left or right margin is
crossed.
See the
leftright
option for more information.
This option affects the display algorithm used by
vi,
holding off display updating during input of new text to improve
throughput when the terminal in use is slow and unintelligent.
This option is not yet implemented.
If this option is turned on,
vi
historically read startup files that were owned by someone other than
the editor user.
See the section entitled
"Startup Information"
for more information.
This option is a security problem of immense proportions,
and should not be used under any circumstances.
This option will never be implemented.
This option sets tab widths for the editor display.
This option sets the maximum number of characters that are considered significant in a tag name. Setting the value to 0 makes all of the characters in the tag name significant.
Sets the list of tags files, in search order, which are used when the editor searches for a tag.
Set the terminal type.
Setting this option causes
ex/vi
to set (or reset) the environmental variable
TERM
.
This option has historically made editor messages less verbose.
It has no effect in this implementation.
See the
verbose
option for more information.
Modify the ~ command to take an associated motion.
If this option is set,
ex/vi
waits for a specific period for a subsequent key to complete a key
mapping (see the
keytime
option).
If the option is not set, the editor waits until enough keys are
entered to resolve the ambiguity, regardless of how long it takes.
Vi only. This option changes how vi does word erase during text input. If this option is set, text is broken up into two classes, blank characters and nonblank characters. Changing from one class to another marks the end of a word.
Vi only. Vi historically bells the terminal for many obvious mistakes, e.g. trying to move past the left-hand margin, or past the end of the file. If this option is set, an error message is displayed for all errors.
Vi
only.
Set the window size if the baud rate is less than 1200 baud.
See the
window
option for more information.
Vi
only.
Set the window size if the baud rate is equal to 1200 baud.
See the
window
option for more information.
Vi
only.
Set the window size if the baud rate is greater than 1200 baud.
See the
window
option for more information.
Ex only. This option causes a warning message to the terminal if the file has been modified, since it was last written, before a ! command.
This option determines the default number of lines in a screenful,
as displayed by the
z
command.
It also determines the number of lines scrolled by the
vi
commands
<control-B>
and
<control-F>,
and the default number of lines scrolled by the
vi
commands
<control-D>
and
<control-U>.
The value of window can be unrelated to the real screen size,
although it starts out as the number of lines on the screen.
See the section entitled
"Sizing the Screen"
for more information.
Setting the value of the
window
option is the same as using the
-w
command line option.
If the value of the
window
option (as set by the
window
,
w300
,
w1200
or
w9600
options) is smaller than the actual size of the screen,
large screen movements will result in displaying only that smaller
number of lines on the screen.
(Further movements in that same area will result in the screen being
filled.)
This can provide a performance improvement when viewing different
places in one or more files over a slow link.
Resetting the window size does not reset the default number of lines scrolled by the <control-D> and <control-U> commands.
Vi
changes the name of the editor's icon/window to the current file name
when it's possible and not destructive, i.e.,
when the editor can restore it to its original value on exit or when
the icon/window will be discarded as the editor exits.
If the
windowname
edit option is set,
vi
will change the icon/window name even when it's destructive and the
icon/window name will remain after the editor exits.
(This is the case for
xterm
(1)).
This option is identical to the
wrapmargin
option, with the exception that it specifies the number of columns
from the
left
margin before the line splits, not the right margin.
If both
wraplen
and
wrapmargin
are set, the
wrapmargin
value is used.
Vi
only.
If the value of the
wrapmargin
option is non-zero,
vi
will split lines so that they end at least that number of columns
before the right-hand margin of the screen.
(Note, the value of
wrapmargin
is
not
a text length.
In a screen that is 80 columns wide, the command
":set wrapmargin=8
"
attempts to keep the lines less than or equal to 72 columns wide.)
Lines are split at the previous whitespace character closest to the
number.
Any trailing whitespace characters before that character are deleted.
If the line is split because of an inserted
<space>
or
<tab>
character, and you then enter another
<space>
character, it is discarded.
If wrapmargin is set to 0,
or if there is no blank character upon which to split the line,
the line is not broken.
If both
wraplen
and
wrapmargin
are set, the
wrapmargin
value is used.
This option causes searches to wrap around the end or the beginning of the file, and back to the starting point. Otherwise, the end or beginning of the file terminates the search.
If this option is set, file-overwriting checks that would usually be
made before the
write
and
xit
commands, or before an automatic write (see the
autowrite
option), are not made.
This allows a write to any file, provided the file permissions allow it.
!
: Description, Description, Description
"
: Description
#
: Description, Description, Description
$
: Description, Description
%
: Description, Description
&
: Description, Description, Description, Description
'<character>
: Description
)
: Description, Description
*
: Description
+
: Description, Description
,
: Description, Description
-
: Description
.
: Description, Description
/RE/
: Description, Description
/RE<carriage-return>
: Description
0
: Description, Description
0<control-D>
: Description, Description
:
: Description, Description
;
: Description, Description
< motion
: Description
<[< ...]
: Description
<control-]>
: Description, Description
<control-^>
: Description, Description
<control-A>
: Description, Description
<control-B>
: Description, Description
<control-D>
: Description, Description, Description, Description, Description
<control-E>
: Description, Description
<control-F>
: Description, Description
<control-G>
: Description, Description
<control-H>
: Description, Description, Description, Description
<control-J>
: Description, Description
<control-L>
: Description, Description
<control-M>
: Description, Description
<control-N>
: Description, Description
<control-P>
: Description, Description
<control-R>
: Description, Description
<control-T>
: Description, Description, Description, Description
<control-U>
: Description, Description
<control-W>
: Description, Description, Description
<control-X>[0-9A-Fa-f]+
: Description
<control-Y>
: Description, Description
<control-Z>
: Description, Description, Description
<end-of-file>
: Description
<erase>
: Description, Description
<escape>
: Description, Description, Description, Description
<interrupt>
: Description, Description, Description, Description, Description
<line erase>
: Description
<literal-next>
: Description
<nul>
: Description, Description
<space>
: Description, Description
<word erase>
: Description
=
: Description, Description
>[> ...]
: Description
?RE<carriage-return>
: Description
?RE?
: Description, Description
@
: Description, Description
[[
: Description, Description
[count] (
: Description
[count] C
: Description
[range]!
: Description
]]
: Description, Description
^
: Description, Description
^<control-D>
: Description, Description
_
: Description, Description
`<character>
: Description, Description
a
: Description, Description
A
: Description, Description
a[ppend][!]
: Description
ab[brev]
: Description
ar[gs]
: Description
b
: Description, Description
B
: Description, Description
bg
: Description, Description
buffer
: Description, Description
c
: Description, Description
c[hange][!]
: Description
cd[!]
: Description
chd[ir][!]
: Description
co[py]
: Description
cs[cope]
: Description
d
: Description, Description
D
: Description, Description
d[elete]
: Description
di[splay]
: Description
e
: Description, Description
E
: Description, Description
e[dit][!]
: Description
ex[!]
: Description
exu[sage]
: Description
f
: Description, Description
F
: Description, Description
f[ile]
: Description
fg
: Description, Description
G
: Description, Description
g[lobal]
: Description
H
: Description, Description
h
: Description
he[lp]
: Description
i
: Description, Description
I
: Description, Description
i[nsert][!]
: Description
J
: Description, Description
j
: Description, Description
j[oin][!]
: Description
k
: Description, Description, Description, Description
L
: Description, Description
l
: Description, Description
l[ist]
: Description
m
: Description, Description
M
: Description, Description
m[ove]
: Description
ma[rk]
: Description
map[!]
: Description
mk[exrc][!]
: Description
n
: Description, Description
N
: Description, Description
n[ext][!]
: Description
nu[mber]
: Description
o
: Description, Description
O
: Description, Description
o[pen]
: Description
p
: Description, Description
P
: Description, Description
p[rint]
: Description
pre[serve]
: Description
prev[ious][!]
: Description
pu[t]
: Description
Q
: Description, Description
q[uit][!]
: Description
r
: Description, Description
R
: Description, Description
r[ead][!]
: Description
rec[over]
: Description
res[ize]
: Description
rew[ind][!]
: Description
s
: Description, Description
S
: Description, Description
s[ubstitute]
: Description
se[t]
: Description
sh[ell]
: Description
so[urce]
: Description
st[op][!]
: Description
su[spend][!]
: Description
t
: Description, Description, Description, Description
T
: Description, Description
ta[g][!]
: Description
tagn[ext][!]
: Description
tagp[op][!]
: Description
tagp[rev][!]
: Description
tagt[op][!]
: Description
u
: Description, Description
U
: Description, Description
u[ndo]
: Description
una[bbrev]
: Description
unm[ap][!]
: Description
v
: Description, Description
ve[rsion]
: Description
vi[sual]
: Description
vi[sual][!]
: Description
viu[sage]
: Description
vs[plit][!]
: Description
w
: Description, Description
W
: Description, Description
w[rite]
: Description
w[rite][!]
: Description
wn[!]
: Description
wq[!]
: Description
x
: Description, Description
X
: Description, Description
x[it][!]
: Description
y
: Description, Description
Y
: Description, Description
ya[nk]
: Description
z
: Description, Description, Description, Description
ZZ
: Description, Description
{
: Description, Description
|
: Description, Description
}
: Description, Description
~
: Description, Description, Description, Description, Description, Description