Manual Page Result
0
Command: vedit | Section: 1 | Source: Digital UNIX | File: vedit.1.gz
vi(1) General Commands Manual vi(1)
NAME
vi, vedit, view - Edits files with a full screen display
SYNOPSIS
Normal Syntax
vi [-ls] [-R] |[-r] [-c subcommand] [-t tag] [-w number] [-x] [-v]
[+[subcommand]] [-] [file...]
Read-only Syntax
view [-l] [-R] |[-r] [-t tag] [-c subcommand] [-w number] [-x] [-v]
[+[subcommand]] [-] [file...]
Novice Version Syntax
vedit [-l] [-R] |[-r] [-t tag] [-w number] [-x] [-v] [-] [file...]
The vi command is a display editor that is based on an underlying line
editor (ex).
STANDARDS
Interfaces documented on this reference page conform to industry stan-
dards as follows:
vi: XPG4, XPG4-UNIX
vedit: XPG4, XPG4-UNIX
view: XPG4, XPG4-UNIX
ex: XPG4, XPG4-UNIX
Refer to the standards(5) reference page for more information about in-
dustry standards and associated tags.
OPTIONS
Performs the specified ex subcommand before editing begins.
This subcommand may actually consist of several commands sepa-
rated by vertical line (|) characters. Indents appropriately
for LISP code, and accepts the (, ), {, }, [, and ] characters
(parentheses, braces, and brackets) as text rather than inter-
preting them as vi subcommands. The LISP modifier is active in
open or visual modes. Recovers file after an editor or system
crash. If you do not specify a file, vi displays a list of all
saved files. [DIGITAL] Invokes vi in open mode. (Silent
mode.) Sets the readonly option to protect the file against
overwriting.
[DIGITAL] This option is automatically invoked if you use the
view command. Edits the file containing the tag and positions
the editor at its definition. To use this option, you must
first create a database of function names and their locations
using the ctags command. [DIGITAL] Invokes the visual editor.
When the -v option is specified, an enlarged set of subcommands
is available, including screen editing and cursor movement fea-
tures. This option has no effect when vi is specified, but is
honored for compatibility with historical conventions. Sets the
default window size to number. This is useful when you use the
editor over a low-speed line. [DIGITAL] Prompts for an encryp-
tion key and then unencrypts the file. If the file specified is
not encrypted or an incorrect key is entered, garbled text is
displayed. [DIGITAL] Suppresses all interactive user feedback.
If you use this option, file input/output errors do not generate
an error message. Performs the ex subcommand before editing be-
gins. If you do not specify subcommand, the cursor is placed on
the last line of the file. This option is obsolescent.
This subcommand may actually consist of several commands sepa-
rated by vertical line (|) characters.
OPERANDS
The file argument specifies the files to be edited. If you supply more
than one file on the command line, vi edits each file in the order
specified.
DESCRIPTION
The ex editor subcommands can be used within the vi editor, because vi
is based on ex. The view command is a read-only version of vi; the
readonly option is set to protect files during browsing. The vedit
command is a version of vi intended for beginners. In it, the report
option is set to 1, the showmode option is set, and the novice option
(making vedit a line editor, rather than a screen editor) is set. (For
more information on these options, see Setting Options.)
When you use vi, changes you make to a file are reflected on your dis-
play. The position of the cursor on the display indicates its position
within the file. The subcommands affect the file at the cursor posi-
tion.
[DIGITAL] You can encrypt a file using the :X subcommand. Ensure that
you remember the encryption key because an easy means to unencrypt a
file does not exist. Only the first 6 characters of a key are signifi-
cant.
Limitations of the vi Editor
The maximum limits of the vi editor are as follows: [DIGITAL] 2048
bytes per line [DIGITAL] 256 bytes per global command list [DIGI-
TAL] 128 bytes in the previous inserted and deleted text [DIGI-
TAL] 128 bytes in a shell escape command [DIGITAL] 128 bytes in a
string-valued option [DIGITAL] 30 bytes in a tag name [DIGITAL] 128
map macros with 2048 bytes total.
Editing Modes
The vi editor has the following operational modes: When you start the
vi editor, it is in Command mode. Any subcommand can be entered from
this mode, except commands that can only be used in the Text Input mode
(those subcommands that make corrections during text insertion). When
subcommands and the other modes end, vi returns to Command mode.
Pressing the <Esc> key cancels a partial subcommand. Entered by the a,
A, i, I, o, O, cx (where x represents the scope of the subcommand), C,
s, S, and R subcommands. After entering one of these commands, you can
enter text into the editing buffer at the current cursor position. To
return to Command mode, press <Esc> for normal exit or press the Inter-
rupt key sequence to end abruptly. Some subcommands (those with the
prefix : (colon), / (slash), ? (question mark), or !!) read input on a
line displayed at the bottom of the screen. When you enter the initial
character, vi places the cursor at the bottom of the screen, where you
enter the remaining characters of the command. Press <Return> to per-
form the subcommand and enter the Interrupt key sequence to cancel it.
When !! is used, the cursor moves only after the two exclama-
tion points are entered. When : is used, special meaning is
given to the following characters if used as counts before a
command: All lines, regardless of cursor position Last line Cur-
rent line
Setting Options
The vi editor allows you to customize options so that you can use the
editor for a specific task. Use the set command to set or change an
option. To view the current setting of all options, enter :set all
while in vi Command mode. To view the current setting of options that
may be set to a value, enter a line of the form :set option.
Some options are set to a string or a number value; other options are
simply turned on or off. To change an option that is set to a value,
enter a command in the form :set option=value. To toggle an option that
can be set to on or off, enter a line of the form :set option to set it
to on or :set nooption to set it to off.
Options can be abbreviated in a set command. The following table lists
some of vi's options, along with abbreviations and descriptions:
l l lw(2.7i). Option Abbreviation Description [no]autoin-
dent ai T{ Indents automatically in Text mode to the indentation on
the previous line by using the spacing between tab stops specified by
the shiftwidth option. The default is noai. To back the cursor up to
the previous tab stop, type <Ctrl-d>. This option is not in effect for
global commands. T} [no]autoprint ap T{ Prints the current line af-
ter any command that changes the editing buffer. The default is ap.
This option applies only to the last command in a sequence of commands
on a single line, and is not in effect for global commands. T} [no]au-
towrite aw T{ Writes the editing buffer to the file automatically
before the :n, :ta, <Ctrl-a>, and ! subcommands if the editing buffer
was changed since the last write command. The default is noaw. T}
[no]beautify bf T{ Prevents user from entering control characters
(except for tab, newline, and formfeed) in the editing buffer during
text entry. The default is nobf. This option does apply to command
input. T} closepunct cp= T{ The default is cp='".,;)]}. T} di-
rectory dir= T{ Displays the directory that contains the editing
buffer. The default is dir=/var/tmp. T} [no]edcompatible ed T{
Retains global (g) and confirms (c) subcommand suffixes during multiple
substitutions and causes the read (r) suffix to work like the r subcom-
mand. The default is noed. T} [no]errorbells eb T{ Precedes error
messages with an <Alert> character. Setting this option off (noeb) does
not suppress the alerting in visual mode. The default is noeb. T}
[no]exrc "! T{ If not set, ignores any file in the current directory
during initialization, unless the current directory is that named by
the HOME variable. The default is noexrc. T} [no]flash fl T{ Uses
visual flash rather than audible bell. The default is fl. T} hard-
tabs ht= T{ Tells vi the distance between the hardware tab stops on
your display. The default is ht=8. T} [no]ignorecase ic T{ Ignores
the distinction between uppercase and lowercase while searching for
regular expressions. The default is noic. T} [no]lisp lisp T{ Enters
vi in LISP mode. In this mode, vi appropriately indents for LISP code
and the (, ), {, }, [[, and ]]. The default is nolisp. T}
[no]list list T{ Displays text with tabs and the end of lines marked.
Tabs are displayed as ^I and the end of lines as $. The default is no-
list. T} [no]magic magic T{ Treats the characters [, and * as spe-
cial characters in scans. In Off mode, only the (, ), and $ characters
retain special meanings; however, special meaning of other characters
can still be invoked by preceding the character with a \ (backslash).
The default is magic. T} [no]mesg mesg T{ Permits other users to use
the talk or write commands to write to the terminal when in visual
mode. The shell level mesg n command takes precedence over the mesg
option. If a mesg y command was issued before vi (or ex) was started,
set nomesg can be used to suppress message, but a set mesg input can
not override a mesg n command. The default is mesg. T} [no]mode-
line modeline T{ Runs an editor command line if found in the first
five and the last five lines of the file. An editor command line may
be anywhere in a line. To be recognized as a command line, it must
contain a space or a tab followed by the string ex: or vi:. The com-
mand line is ended by a second : (colon). The editor tries to inter-
pret any data between the first and second : as editor commands. The
default is nomodeline. T} [no]novice novice T{ The default is
nonovice. T} [no]number nu T{ Displays lines prefixed with their
line numbers. The default is nonu. T} [no]optimize opt T{ Speeds
up the operation of terminals that do not have cursor addressing. The
default is noopt. T} paragraphs para= T{ Defines macro names
that start paragraphs. The default is para=IPLPPPQPP LIpplpipnpbp.
Single letter nroff macros, such as
must include the space as a quoted character if respecifying a para-
graph. T} partialcharacter pc= T{ The default is pc=-. T}
[no]prompt prompt T{ Prompts for command mode input with a :
(colon). When not set, no prompt is displayed. The default is prompt.
T} readonly " T{ Allows writing to a different file. In addition,
the write can be forced by using the ! (exclamation point) character
(see the editor command write). The default is off, unless the file
lacks write permission or the -R option is specified. T} [no]re-
draw re T{ Simulates a smart display on a dumb display. The de-
fault is nore. T} [no]remap remap T{ Enables following of map
keys. For example, if remap is set, map u k map r u causes r to map to
k. If noremap is set, r maps to u. The default is remap. T} re-
port report= T{ Sets the number of repetitions of a command before
a message is displayed. For subcommands that can produce a number of
messages, such as global subcommands, the messages are displayed when
the command is completed. The default is report=5. T}
scroll scr= T{ Sets the number of lines to be scrolled when you
scroll the screen up or down. The default scroll is one-half the size
of the screen. T} sections sect= T{ Defines macro names that
start sections. The default is sect=NHSHH HUuhsh+c. Single letter
nroff macros, such as
must include the space as a quoted character if respecifying a para-
graph. T} shell sh= T{ Defines the shell for ! or :! commands.
The default is the value of the SHELL environment variable. T}
shiftwidth sw= T{ Sets the distance for the software tab stops
used by autoindent, the shift commands (> and <), and the text input
commands (<Ctrl-d> and <Ctrl-t>) to allow the editor to indent text and
move back to a previous indentation. The default is sw=8. T}
[no]showmatch sm T{ Shows the matching open parenthesis ( or open
brace { as you type the close parenthesis ) or close brace }. The de-
fault is nosm. T} [no]showmode smd T{ Displays mode indicator at
the bottom of the screen when in the insert or replace mode. The de-
fault is nosmd. T} [no]slowopen slow T{ Postpones updating the dis-
play during inserts. The default is noslow. T} [no]sourceany T{
Allows the use of the source command on a file that a user does not
own. The default is nosourceany. T} tabstop ts= T{ Sets the dis-
tance between tab stops when a file is displayed. The default is ts=8.
T} taglength tl= T{ Determines length of tag. The default is tl=0.
T} [no]tags tag T{ Specifies a list of possible file names of tag
files. The default is tag=tags /usr/lib/tags. T} term term= T{
Sets the kind of display you are using. The default is term=$TERM,
where $TERM is the value of the TERM shell variable. T}
[no]terse terse T{ Allows vi to display the short form of messages.
The default is noterse. T} [no]timeout to T{ Sets a time limit of
2 seconds on entry of characters. This limit allows the characters in
a macro to be entered and processed as separate characters when timeout
is set. To resume use of the macro, set notimeout. The default is to.
T} ttytype tty= Same as term. [no]warn warn T{ Displays a warning
message before the ! subcommand executes a shell command if this is
the first time you issued a shell command after a given set of changes
were made in the editing buffer, but not written to a file. The de-
fault is warn. T} window wi= T{ Sets the number of lines displayed
in one window of text. The default is dependent on the baud rate at
which you are operating: 600 baud or less / 8 lines, 1200 baud
/ 16 lines, higher speeds / full screen minus 1. T} wrapmar-
gin wm= T{ Sets the margin for automatic wordwrapping from one
line to the next. A value of 0 indicates no wordwrapping. The default
is wm=0. T} [no]wrapscan ws T{ Allows string searches to wrap from
the end of the editing buffer to the beginning. The default is ws. T}
wraptype wt= T{ (For editing Japanese) Controls wrapping of Japanese
words. Setting wraptype=general causes general-purpose wrap on word
breaks, where word break is defined as whitespace or space between two
nonASCII characters. Setting wraptype=general is a combination of word
and flexible. Setting wraptype=word causes wrap on words. Setting
wraptype=rigid causes wrap on column and before closing punctuation.
Setting wraptype=flexible causes wrap on column, but closing punctua-
tion may extend past the margin. The default is wt=word. T}
[no]writeany wa T{ Turns off the checks usually made before a write
command. The default is nowa. T}
Defining Macros
If you use a subcommand or sequence of subcommands frequently, you can
create a macro that issues the subcommand or sequence when you call a
macro. To create a macro, enter the sequence of subcommands into an
editing buffer named with a letter of the alphabet. When used as
buffer names, lowercase ASCII letters a through z overlay the contents
of the buffer, while uppercase ASCII letters A through Z append text to
the previous contents of the buffer, allowing the building of a macro
piece by piece.
To invoke the macro, enter @x, where x is the letter name of the
buffer. Enter @@ to repeat the last macro you invoked.
Mapping Keys
You can use the map command to set a keystroke to a subcommand or a se-
quence of subcommands. To set a key mapping, enter :map key subcommand
where key is the key to which you want to assign a subcommand or se-
quence of subcommands and subcommand is the subcommand or sequence of
subcommands. For example, to set @ to delete lines, enter: :map @ dd
In this example, @ is the key to which the subcommand is assigned and
dd is the subcommand.
In the next example, a subcommand sequence is mapped to a key: :map *
{>}
The * (asterisk) is the key to which the subcommand sequence is as-
signed and {>} is the subcommand sequence. The { (open brace) moves
the cursor to the beginning of the paragraph and the > (right angle
bracket) indents the paragraph to the next shiftwidth.
To display the list of the current key mappings while you are in Com-
mand mode, enter the :map command. You can also remove a key mapping.
To remove a key mapping, enter :unmap string or :unmap! string where
string is the string used after the :map command to set the key and
subcommand sequence. For example, to remove key mapping for the previ-
ous example, enter: :unmap *
If function keys are defined for your terminal, they can be put in a
map or unmap command by typing <Ctrl-v> then pressing the desired key.
In this way, function keys that are unused during editing can be mapped
to useful editing subcommand sequences.
If the ! (exclamation point) character is appended to the command name
map (map!), the mapping is effective during input mode rather than dur-
ing visual mode.
Abbreviations
You can define abbreviations for long phrases that you use often. The
vi editor then automatically expands these abbreviations whenever you
enter them in insert mode. Only single-byte characters can appear in
abbr_string; abbr_string cannot contain Asian multibyte characters.
To define an abbreviation, enter: :abbr abbreviation phrase
where abbreviation is the abbreviation you specify for the longer text
specified by phrase. For example, to specify the abbreviation imho for
the phrase In my humble opinion, enter: :abbr imho In my humble opinion
Keeping a Customized Change
When you customize vi from the vi command line, the customized editor
is in effect until you exit the editor. If you want to reuse such
things as option settings and key mappings, you must put them in the
file in your home directory or define the EXINIT environment variable.
The vi editor processes the commands given in the EXINIT variable or
reads the file each time you invoke it. Here is an example of an file:
set ai aw set wm=5 map @ dd
Users with both a file and an EXINIT environment variable will find
that the vi editor no longer reads the file. This change was made to
meet the specifications of XPG4.
The standard provides for an approximation of the old behavior. A new
variable, named exrc, is defined. When this variable is set by the com-
mands in the EXINIT environment variable, the editor reads in the cur-
rent directory for additional startup commands. For example: setenv EX-
INIT 'set ai terse magic bf wm=1 exrc'
[DIGITAL] Additionally, the editor refuses to read the file if its
mode grants write permission to anyone other than the owner; this re-
striction prevents certain security breaches. No overt indication is
given when such a refusal occurs.
vi Character Sets
The collation sequence, as defined by the value of the LC_COLLATE envi-
ronment variable, defines the alphanumeric set used by your system.
This table affects the performance of vi macros and subcommands.
The vi editor uses the collation sequence to distinguish between a
small word and a big word. A small word is bounded by letters or num-
bers as defined in the collation table. For example, isn't is two
small words. The ' (apostrophe) is not a number or an alphabetic char-
acter, and it bounds both the small word t and the small word isn. A
big word is bounded by spaces, tabs, or newline indicators. For exam-
ple, stop is a big word. For more information, see the section Moving
to Words.
Subcommand Syntax
[named_buffer] [operator] [number] argument
Surrounding brackets indicate optional items. A temporary text storage
area. Specifies the subcommand or action; instructs the vi editor. A
whole decimal value that specifies either the extent of the action or a
line address. The vi editor interprets this number in one of the fol-
lowing ways: Go to line number: 5G 10z<Return> Go forward number
columns. 25<Space> Scroll number of lines: 10<Ctrl-d> 10<Ctrl-u>
Delete number lines: 6dd The % means all. To yank all lines: %y
(The preceding command replaces 1,$y.) Specifies what to act
on. This can be a text object (a character, word, sentence,
paragraph, section, or character string) or a text position (a
line, position in the current line, or screen position).
Moving Within a File
Enter the following subcommands in Command mode. You can cancel an in-
complete subcommand by pressing the <Esc> key. Moves the cursor one
character to the left. Moves the cursor down one line, remaining in
the same column. Moves the cursor up one line, remaining in the same
column. Moves the cursor one character to the right.
Long lines: Lines over one screen width are wrapped but not
broken. When using the Up Arrow or Page Up key, @ lines are
added at the bottom of the screen when too few physical lines
are available to display the complete line. The Down Arrow key
moves the entire line off the screen at once.
Character Positioning Within a Line
Enter the following subcommands in Command mode. Moves the cursor to
the first nonspace character. Moves the cursor to the beginning of the
line. Moves the cursor to the end of the line. Moves the cursor to
the next x character. Moves the cursor to the last x character. Moves
the cursor to one column before the next x character. Moves the cursor
to one column after the last x character. Repeats the last f, F, t, or
T subcommand. Repeats the last f, F, t, or T subcommand in the oppo-
site direction. Moves the cursor to the specified column.
Moving to Words
Enter the following subcommands in Command mode. Moves the cursor to
the next small word. Moves the cursor to the previous small word.
Moves the cursor to the end of the next small word. Moves the cursor
to the next big word. Moves the cursor to the previous big word.
Moves the cursor to the end of the next big word.
Moving by Line Positioning
Enter the following subcommands in Command mode. Moves to the line
number given as preceding argument, or the end of the file if no pre-
ceding count is given. Moves the cursor to the top line on the screen.
Moves the cursor to the last line on the screen. Moves the cursor to
the middle line on the screen. Moves the cursor to the next line, at
its first nonspace character. Moves the cursor to the previous line,
at its first nonspace character. Moves the cursor to the next line, at
its first nonspace character.
Moving to Sentences, Paragraphs, or Sections
Enter the following subcommands in Command mode. You can cancel an in-
complete subcommand by pressing the <Esc> key. Places the cursor at
the beginning of the previous sentence (or the previous S-expression if
you are in LISP mode). Places the cursor at the beginning of the next
sentence (or the next S-expression if you are in LISP mode). Places
the cursor at the beginning of the previous paragraph (or at the next
list if you are in LISP mode). Places the cursor at the beginning of
the next paragraph, at the next section if you are in C mode, or at the
next list if you are in LISP mode. Requires a count; the cursor is
placed in that column (if possible). Places the cursor at the next
section, or function if you are in LISP mode. Places the cursor at the
previous section, or function if you are in LISP mode.
Paging and Scrolling
Scrolls up (default 12 lines). Scrolls down (default 12 lines). Pages
forward one screen. Pages backward one screen. Scrolls the window up
one line. Scrolls the window down one line. Moves to the first non-
white character in the next line. A count specifies the number of
lines to go forward. Inserts shiftwidth white space in input mode, if
at the beginning of the line or preceded only by white space. This in-
serted space can only be backed over using <Ctrl-d>. Cancels a par-
tially formed command; sounds the bell if there is none.
In input mode, terminates input mode.
When entering a command on the bottom line of the screen (ex
command line or search pattern with / or ?), terminates input
and executes command. Pages up. Pages down.
Searching for Patterns
The following commands allow you to search for patterns within a file.
Patterns can be regular expressions as described for grep. Places the
cursor at the next line containing pattern. Repeats the last search
for pattern in the direction of the end of the file. Places the cursor
at the next previous line containing pattern. Repeats the last search
for pattern in the direction of the beginning of the file. Repeats the
last search for pattern in the same direction. Repeats the last search
for pattern in the opposite direction. Places the cursor at the num-
berth line after the line matching pattern. Places the cursor at the
numberth line before the line matching pattern. Finds the parenthesis
or brace that matches the one at the current cursor position.
Marking and Returning
Enter the following subcommands in Command mode. You can cancel an in-
complete subcommand by pressing the <Esc> key. Moves the cursor to the
same cursor position of the previous current line. Moves the cursor to
the beginning of the previous current line. Marks the current position
with the letter specified by x. Moves the cursor to the same cursor
position of line marked x. Moves the cursor to the beginning of the
line marked x.
Adjusting the Screen
Enter the following subcommands in Command mode. An incomplete subcom-
mand can be canceled by pressing the <Esc> key. Clears and redraws the
screen. Redraws the screen and eliminates blank lines marked with a @.
Redraws the screen with the current line at the top of the screen. Re-
draws the screen with the current line at the bottom of the screen.
Redraws the screen with the current line at the center of the screen.
Redraws the screen with the line containing pattern at the top. Re-
draws the screen with the line containing pattern at the top. Redraws
the screen with the line containing pattern at the bottom. Redraws the
screen with the line containing pattern at the center. Makes the win-
dow number lines long.
Adding Text to a File--Text Input Mode
The following subcommands are entered in Command mode and bring the vi
editor into Text Input mode to allow you to add text to your file. End
Text Input mode by pressing the <Esc> key. Inserts text after the cur-
sor. Adds text to the end of the line. Inserts text before the cur-
sor. Inserts text before the first nonspace character in the line.
Adds an empty line below the current line. Adds an empty line above
the current line.
Changing Text While in Input Mode
Use the following commands only while in Text Entry mode. They have
different meanings in Command mode. Erases the last character. Erases
the last small word. (For more information about small words, see the
section vi Character Sets.) Quotes the Erase and Kill characters.
Ends insertion, back to Command mode. Interrupts, terminates insert or
<Ctrl-d>. Goes back to the previous autoindent stop. Ends autoindent
for this line only. Moves the cursor back to the left margin. Quotes
a nonprinting character.
Changing Text from Command Mode
Use the following subcommands in Command mode. An incomplete subcom-
mand can be canceled by pressing the <Esc> key. Changes the rest of
the line (c$). Must be followed by a movement command. Deletes the
specified region of text and enters input mode to replace it with the
entered text. If more than part of a single line is affected, the
deleted text is saved in the numeric buffers. If only part of the cur-
rent line is affected, the last character to be deleted is marked with
a $. A count is passed through to the move command. If the command is
cc, the whole of the current line is changed. Changes a line. Changes
a word. Deletes the rest of the line (d$) and puts it into the undo
buffer. Must be followed by a movement command. Deletes the specified
region of text. If more than part of a line is affected, the text is
saved in the numeric buffers. A count is passed through to the move
command. If the command is dd, the whole of the current line is
deleted. Deletes a line and puts it into the undo buffer. Deletes a
word and puts it into the undo buffer. Joins lines. Replaces the cur-
rent character with the character specified by x. Overwrites charac-
ters. Substitutes characters (cl). Substitutes lines (cc). Undoes
the previous change. Deletes a character. Deletes characters before
cursor (dh). Shifts one line to the left. Shifts all lines from the
cursor to the end of the screen to the left. (The < character de-
scribes a range upon which the L subcommand acts.) Shifts one line to
the right. Shifts all lines from the cursor to the end of the screen
to the right. (The > character describes a range upon which the L sub-
command acts.) Changes the letter at the cursor to the opposite case.
Copying and Moving Text
Use the following subcommands in Command mode. An incomplete subcom-
mand can be canceled by pressing <Esc>. Puts back text in the undo
buffer after (before) the cursor. Puts back text from the buffer x af-
ter (before) the cursor. You must precede the character x with a dou-
ble quote. Deletes object into the buffer x. You must precede the
character x with a double quote. Yanks object into the undo buffer
(for example, yw to yank a word). Yanks object into buffer x. You
must precede the character x with a double quote. Places the line in
the undo buffer.
Restoring and Repeating Changes
Use the following subcommands in Command mode. An incomplete subcom-
mand can be canceled by pressing the <Esc> key. Undoes the last com-
mand. Restores the current line if the cursor has not left the line
since the last change. Repeats the last change or increments the np
command.
Note that this command is not meant for use with a macro. Enter
@@ to repeat a macro. Retrieves the nth last delete of a com-
plete line or block of lines. You must precede the character n
with a double quote.
Saving Changes to a File
Use the following subcommands in Command mode. An incomplete subcom-
mand can be canceled by pressing <Esc>. If you are using these subcom-
mands within the ex editor, do not type the : (colon). Writes the
editing buffer contents to the original file. Writes the editing
buffer contents to the named file. Overwrites file with the editing
buffer contents. [DIGITAL] Prompts you to enter an encryption key.
When you save the file, it is written in encrypted form. For subse-
quent edits of the encrypted file, use the -x option to display the
file in its unencrypted form.
Interrupting, Cancelling, and Exiting vi
Enters the ex editor in Command mode. Exits vi, saving changes, if any
were made. Quits vi. If you have changed the contents of the editing
buffer, vi displays a warning message and does not quit. Quits vi,
discarding the editing buffer with no warning. Runs a shell. You can
return to vi by pressing <Ctrl-d>. Runs the file through the specified
shell command (causes no change to the file). Runs command, then re-
turns. Repeats the last :!command command. Executes the shell command
identified by command and replaces the number of lines specified by n
with the output of command. If n is not specified, the default is 1.
If command expects standard input, the lines specified are used as in-
put. (10!!sort sorts the next 10 lines.) Works like n!!command, ex-
cept that lines is a line address (for example, !Gsort sorts the rest
of the file). Interrupts a subcommand.
Editing a Second File
Enter the following subcommands in Command mode. An incomplete subcom-
mand can be canceled by pressing the <Esc> key. Edits file. If you
are using this subcommand from the ex editor, do not type the :
(colon). Reedits the current file and discards all changes. Edits
file, starting at the end. Edits file, starting at the line number.
Edits the alternate file. The alternate file is usually the previous
current file name. However, if changes are pending on the current file
when a new file is called, the new file becomes the alternate file.
Reads the file into the editing buffer by adding new lines below the
current line. If you are using this subcommand from the ex editor, do
not type the : (colon). Runs the shell command identified by command
and places its output in the file by adding new lines below the current
cursor position.
Using a Tags File
The ctags command makes a tags file from the specified C, Pascal, FOR-
TRAN, yacc, lex, or LISP source files. A tags file gives the locations
of function and type definitions in a group of files. To use the next
three commands, you must first create a database of function names and
their locations (called a tags file) using the ctags command. Edits a
file containing tag at the location of tag. If the tag is in another
file and the current file has been changed (and noaw is set), a warning
is posted. If you are using this subcommand from the ex editor, do not
type the : (colon). Finds the word at the cursor in the tags file
then displays the proper file, placing the cursor at the tag. If the
tag is in the current file, moves cursor to it. Same as :ta, but the
tag is the word to the right of the cursor. Returns to the file and
line where the cursor was positioned when <Ctrl-]> was entered.
Editing a List of Files
Enter the following subcommands in Command mode. Edits the next file
in the list entered on the command line. Specifies a new list of files
to edit.
Displaying File Information
[DIGITAL] Enter the following subcommand in Command mode to show the
current file name, the current line number, the number of lines in the
file, and the percentage of lines of the file that are before the cur-
sor:
<Ctrl-g>
EXIT STATUS
The following exit values are returned: Successful completion. An er-
ror occurred.
ASYNCHRONOUS EVENTS
The following actions are taken upon receipt of signals: The current
editor command is aborted and vi returns to the command level and
prompts for another command. The screen is refreshed if in visual
mode. If the current buffer has changed since the last e or w command,
vi attempts to save the current file in a state such that it can be re-
covered later by an ex -r or vi -r command.
ENVIRONMENT VARIABLES
The following environment variables affect the execution of vi: Over-
rides the system-selected horizontal screen size. Determines a list of
ex commands to be executed at startup before the first file is read.
The list can include multiple commands separated by a vertical line (|)
character. Determines the pathname of a directory searched at startup
for a file named Provides a default value for the internationalization
variables that are unset or null. If LANG is unset or null, the corre-
sponding value from the default locale is used. If any of the interna-
tionalization variables contain an invalid setting, the utility behaves
as if none of the variables had been defined. If set to a non-empty
string value, overrides the values of all the other internationaliza-
tion variables. Determines the locale for the behavior of ranges,
equivalence classes, and multicharacter collating elements within regu-
lar expressions. Determines the locale for the interpretation of se-
quences of bytes of text data as characters (for example, single-byte
as opposed to multibyte characters in arguments and input files), the
behavior of character classes within regular expressions, the classifi-
cation of characters as upper- or lower-case letters, the case conver-
sion of letters, and the detection of word boundaries. Overrides the
system-selected vertical screen size, used as the number of lines in a
screenful and the vertical screen size in visual mode. Determines the
locale for the format and contents of diagnostic messages written to
standard error. Determines the location of message catalogues for the
processing of LC_MESSAGES. Determines the search path for the shell
command specified in the editor commands shell, read and write and the
visual-mode command !. Determines the preferred command-line inter-
preter for use in !, shell, read and other commands with an operand of
the form !string. For the shell command the program will be invoked
with the single argument -i, for all others it will be invoked with the
two arguments -c and string. If this variable is null or not set, the
sh command will be used. Determines the name of the terminal type. If
this variable is unset or null, a default terminal type that provides
most capabilities is used.
SEE ALSO
Commands: ctags(1), edit(1), ed(1), ex(1), grep(1), mesg(1), nroff(1),
sed(1)
Files: terminfo(4)
Environment: environ(5)
Standards: standards(5)
vi(1)