|HP-UX Reference > V
vi(1)HP-UX 11i Version 3: February 2007
vi, view, vedit — screen-oriented (visual) text editor
vi [-] [-l] [-r] [-R] [-t tag] [-v] [-V] [-w size] [-x] [-C] [+ command] [file]...
vi [-rR] [+command] [-t tag] [-w size] [file]...
view [-] [-l] [-r] [-R] [-t tag] [-v] [-V] [-w size] [-x] [-C] [+ command] [file]...
vedit [-] [-r] [-R] [-l] [-t tag] [-v] [-V] [-w size] [-x] [-C] [+ command] [file]...
The vi (visual) program is a display-oriented text editor that is based on the underlying ex line editor (see ex(1)). It is possible to switch back and forth between the two and to execute ex commands from within vi. The line-editor commands and the editor options are described in ex(1). Only the visual mode commands are described here.
The view program is identical to vi except that the readonly editor option is set (see ex(1)).
The vedit program is somewhat friendlier for beginners and casual users. The report editor option is set to 1, and the nomagic, novice, and showmode editor options are set.
In vi, the terminal screen acts as a window into a memory copy of the file being edited. Changes made to the file copy are reflected in the screen display. The position of the cursor on the screen indicates the position within the file copy.
The environment variable TERM must specify a terminal type that is defined in the terminfo database (see terminfo(4)). Otherwise, a message is displayed and the line-editor is invoked.
As with ex, editor initialization scripts can be placed in the environment variable EXINIT, or in the file .exrc in the current or home directory.
vi recognizes the following command-line options:
(Under UNIX Standard only, see standards(5)) If both the -t tag and -c command (or the obsolescent +command) options are given, the -t tag will be processed first, that is, the file containing the tag is selected by -t and then the command is executed.
When invoked, vi is in command mode. input mode is initiated by several commands used to insert or change text.
In input mode, ESC (escape) is used to leave input mode; however, two consecutive ESC characters are required to leave input mode if the doubleescape editor option is set (see ex(1)).
In command mode, ESC is used to cancel a partial command; the terminal bell sounds if the editor is not in input mode and there is no partially entered command.
WARNING: ESC completes a "bottom line" command (see below).
The last (bottom) line of the screen is used to echo the input for search commands (/ and ?), ex commands (:), and system commands (!). It is also used to report errors or print other messages.
The receipt of SIGINT during text input or during the input of a command on the bottom line terminates the input (or cancels the command) and returns the editor to command mode. During command mode, SIGINT causes the bell to be sounded. In general the bell indicates an error (such as an unrecognized key).
Lines displayed on the screen containing only a ~ indicate that the last line above them is the last line of the file (the ~ lines are past the end of the file). Terminals with limited local intelligence might display lines on the screen marked with an @. These indicate space on the screen not corresponding to lines in the file. (These lines can be removed by entering a ^R, forcing the editor to retype the screen without these holes.)
If the system crashes or vi aborts due to an internal error or unexpected signal, vi attempts to preserve the buffer if any unwritten changes were made. Use the -r command line option to retrieve the saved changes.
The vi text editor supports the SIGWINCH signal, and redraws the screen in response to window-size changes.
Most commands accept a preceding number as an argument, either to give a size or position (for display or movement commands), or as a repeat count (for commands that change text). For simplicity, this optional argument is referred to as count when its effect is described.
The following operators can be followed by a movement command to specify an extent of text to be affected: c, d, y, <, >, !, and =. The region specified begins at the current cursor position and ends just prior to the cursor position indicated by the move. If the command operates on lines only, all the lines that fall partly or wholly within this region are affected. Otherwise the exact marked region is affected.
In the following description, control characters are indicated in the form ^X, which represents Ctrl-X. Whitespace is defined to be the characters space, tab, and alternative space. Alternative space is the first character of the ALT_PUNCT item described in langinfo(5) for the language specified by the LANG environment variable (see environ(5)).
Unless otherwise specified, the commands are interpreted in command mode and have no special effect in input mode.
Keyboard Editing Keys
At initialization, the editor automatically maps some terminal keyboard editing keys to equivalent visual mode commands. These mappings are only established for keys that are listed in the following table and defined in the terminfo(4) database as valid for the current terminal (as specified by the TERM environment variable).
Both command and input mode mappings are created (see the map command in ex(1)). With the exception of the insert char keys, which simply toggle input mode on and off, the input mode mappings exit input mode, perform the same action as the command mode mapping, and then reenter input mode.
On certain terminals, the character sequence sent by a keyboard editing key, which is then mapped to a visual mode command, can be the same character sequence a user might enter to perform another command or set of commands. This is most likely to happen with the input mode mappings; therefore, on these terminals, the input mode mappings are disabled by default. Users can override the disabling and enabling of both the command and input mode keyboard editing key mappings by setting the keyboardedit and keyboardedit! editor options as appropriate (see ex(1)). The timeout, timeoutlen, and doubleescape editor options are alternative methods of addressing this problem.
For information about the UNIX standard environment, see standards(5).
International codes and environment variables are explained in this section.
COLUMNS overrides the system-selected horizontal screen size.
LINES overrides the system-selected vertical screen size, used as the number of lines in a screenful and the vertical screen size in visual mode.
SHELL is a variable that shall be interpreted as the preferred command-line interpreter for use in !, shell, read, and other commands with an operand of the form !string. For the shell command the program shall be invoked with the two arguments -c and string. If this variable is null or not set, the sh utility shall be used.
TERM is a variable that shall be interpreted as the name of the terminal type. If this variable is unset or null, an unspecified default terminal type shall be used.
PATH determines the search path for the shell command specified in the editor commands, shell, read, and write.
EXINIT determines a list of ex commands that will be executed on editor startup, before reading the first file. The list can contain multiple commands by separating them using a vertical line (|) character.
HOME determines a pathname of a directory that will be searched for an editor startup file named .exrc.
LC_ALL This variable shall determine the locale to be used to override any values for locale categories specified by the setting of LANG or any environment variables beginning with LC_.
LC_MESSAGES determines the locale that should be used to affect the format and contents of diagnostic messages written to standard error and informative messages written to standard output.
LC_COLLATE determines the collating sequence used in evaluating regular expressions and in processing the tags file.
LC_CTYPE determines the interpretation of text as single and/or multi-byte characters, the classification of characters as uppercase or lowercase letters, the shifting of letters between uppercase and lowercase, and the characters matched by character class expressions in regular expressions.
LANG determines the language in which messages are displayed.
LANGOPTS specifies options determining how text for right-to-left languages is stored in input and output files. See environ(5).
If LC_COLLATE or LC_CTYPE is not specified in the environment or is set to the empty string, the value of LANG is used as a default for each unspecified or empty variable. If LANG is not specified or is set to the empty string, a default of "C" (see lang(5)) is used instead of LANG. If any internationalization variable contains an invalid setting, the editor behaves as if all internationalization variables are set to "C". See environ(5).
See also the WARNINGS section in ex(1).
vi places the following limits on files being edited.
Maximum Line Length
4096 characters including 2-3 bytes for overhead. Thus, a line length up to 4092 characters should cause no problem.
If you load a file that contain lines longer than the specified limit, the lines are truncated to the stated maximum length. Saving the file will write the truncated version over the original file, thus overwriting the original lines completely.
Attempting to create lines longer than the allowable maximum for the editor produces a line too long error message.
Do not use the -C option to edit unencrypted files. The -C option is meant to be used only on files that are already encrypted. If the -C option is used on files which are not yet encrypted, a write in the edit session is likely to corrupt the file.
vi was developed by the University of California, Berkeley. The 16-bit extensions to vi are based in part on software of the Toshiba Corporation.
ctags(1), ed(1), ex(1), stty(1), write(1), terminfo(4), environ(5), lang(5), regexp(5), standards(5).
The Ultimate Guide to the vi and ex Text Editors, Benjamin/Cummings Publishing Company, Inc., ISBN 0-8053-4460-8, HP part number 97005-90015.