vi (aix)

Edits files with a full-screen display.

Syntax

{ vi } [ -c Subcommand ] [ -l ] [ -R ] [ -tTag ] [ -v ] [ -wNumber] [ -yNumber ] [ -r [ File ] ] [ + [ Subcommand ] ] [ File ... ]

You start the vi editor by specifying the name of the file to be edited.
Since the vi editor is a full-screen editor, you can edit text on a screen-by-screen basis. The vi editor makes a copy of the file you are editing in an edit buffer, and the contents of the file are not changed until you save the changes. The position of the cursor on the display screen indicates its position within the file, and the subcommands affect the file at the cursor position.
[Modes] [Customize] [Flag] [Subcommand Syntax] [Moving] [Searching for Patterns] [Marking a Specific Location in a File and Returning.] [Edit] [Manipulate] [Adjusting the Screen] [Entering Shell Commands] [Interrupting and Ending the vi Editor.]

vi Editing Modes

The vi editor operates in the following modes:

1. command mode
When you start the vi editor, it is in command mode.
You can enter any subcommand except those designated for use only in the text input mode. The vi editor returns to command mode when subcommands and other modes end. Press the Esc key to cancel a partial subcommand.

2. text input mode
You use the vi editor in this mode when you add text. Enter text input mode with any of the following subcommands:
the a subcommand, A subcommand, i subcommand, I subcommand, o subcommand, O subcommand, cx subcommands (where x represents the scope of the subcommand), C subcommand, s subcommand, S subcommand, and R subcommand.

After entering one of these subcommands, you can enter text into the editing buffer.

To return to command mode, press the Esc key for normal exit or press Interrupt (the Ctrl-C key sequence) to end abnormally.

3. last line mode
Subcommands with the prefix read input on a line displayed at the bottom of the screen.

When you enter the initial character, the vi editor places the cursor at the bottom of the screen, where you enter the remaining characters of the command.
Press the Enter key to run the subcommand or Interrupt (Ctrl-C) to cancel it.
When !! is used, the cursor moves only after both exclamation points are entered. When you use : (colon) to enter the last line mode, special meaning is given to the following characters when they are used before commands that specify counts:

Customizing the vi Editor

You can customize the vi editor by:

Flags

-c Subcommand Carries out the ex editor subcommand before editing begins. When a null operand is entered, as in -c '' , the editor places the cursor on the last line of the file.
-r [File] Recovers a file after an editor or system crash. If you do not specify File, the editor displays a list of all saved files.
-R Sets the readonly option to protect the file against overwriting.
-tTag Edits the file containing the Tag and positions the editor at its definition. To use this flag, you must first create a database of function names and their locations using the ctags command.
-v Enters the vi editor in the verbose mode.
-wNumber Sets the default window size to the value specified by Number. This is useful when you use the editor over a low-speed line.
-yNumber Overrides the maximum line setting of 1,048,560 with any value greater than 1024. You should request twice the number of lines that you require as the vi editor uses the extra lines for buffer manipulation.
+[Subcommand] Carries out the ex editor subcommand before editing begins. If you do not specify Subcommand, the cursor is placed on the last line of the file.
[Back]

vi General Subcommand Syntax

[Named_Buffer] [Operator] [Number] Object
Note: Square brackets indicate optional items.
[Named_Buffer] Specifies a temporary text storage area.
[Operator] Specifies the subcommand or action; instructs the vi editor.
[Number] Is a whole decimal value that specifies either the extent of the action or a line address.
Object Specifies what to act on. This can be a text object (a character, word, sentence, paragraph, section, character string) or a text position (a line, position in the current line, screen position). [Back]

Counts before Subcommands

You can put a number in front of many subcommands. The vi editor interprets this number in one of the following ways: Go to the line specified by the Number parameter:
5G
10Z
Go to the column specified by the Number parameter:
25|
Scroll the number of lines up or down specified by the Number parameter:
10Ctrl-U
10Ctrl-D
Note: In the last example, 10Ctrl-U or 10Ctrl-D means to type the number ten, then press the Ctrl-U (up) or Ctrl-D (down) key sequence. [Back]

Moving within a File

The subcommands for moving within a file enable you to move in the following ways:

Editing a File with the vi Editor

The subcommands for editing enable you to perform the following tasks:

Manipulating Files with the vi Editor

The subcommands for manipulating files allow you to do the tasks outlined in the following sections:

Moving within a Line


Moving within a Line by Character Position


Moving to Words


Moving by Line Position


Moving to Sentences, Paragraphs, or Sections


Moving by Redrawing the Screen


Paging and Scrolling


Searching for Patterns


Marking a Specific Location in a File and Returning


Adding Text to a File (Text Input Mode)

Enter the following subcommands in command mode to change the vi editor into text input mode. End text input mode by pressing the Esc key!!

Changing Text While in Input Mode

Use the following subcommands only while in text input mode. They have different meanings in command mode.

Changing Text from Command Mode


Copying and Moving Text


Restoring and Repeating Changes


Saving Changes to a File


Editing a Second File


Editing a List of Files


Finding Out File Information

Ctrl-G - Shows the current file name, current line number, number of lines in the file, and percentage of the way through the file where the cursor is located. [Back]

Adjusting the Screen


Entering Shell Commands

The following subcommands allow you to run an AIX command within the vi editor.
.

Interrupting and Ending the vi Editor


Exit Status

The following exit values are returned:

Input Files

Input files must be text files or files that are similar to text files except for an incomplete last line that is no longer than LINE_MAX -1 bytes in length and contains no NULL characters.
The .exrc files must be text files consisting of ex commands.
By default, vi will read lines from the files to be edited without interpreting any of those lines as any form of editor command.

Implementation Specifics

This command is part of Base Operating System (BOS) Runtime.

Related Information

The view command, ex command, ed command, sed command, tvi command, ctags command.
Editors Overview in AIX Version 3.2 Editing Concepts and Procedures introduces general concepts about editors and describes the main AIX editors.
Understanding Modes and Subcommands in the vi Editor in AIX Version 3.2 Editing Concepts and Procedures describes concepts and tasks specific to the vi editor.
Operating the vi Editor in AIX Version 3.2 Editing Concepts and Procedures provides practical applications and procedures for the vi editor.
Customizing the vi Editor in AIX Version 3.2 Editing Concepts and Procedures provides information and procedures for setting options, mapping keys, and defining macros for the vi editor.
See "Understanding Modes and Subcommands in the vi Editor" in AIX Version 3.2 Editing Concepts and Procedures for a description of concepts and tasks specific to the vi editor.
Enter the following subcommands in command mode. You can cancel an incomplete command by pressing the Esc key. If you need information about the format of vi subcommands, see "vi General Subcommand Syntax".