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
- : (colon),
- / (slash),
- ? (question mark),
- ! (exclamation point), or
- !!
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:
- % - All lines regardless of cursor position
- $ - Last line
- . - Current line
[Back]
Customizing the vi Editor
You can customize the vi editor by:
- Setting editor options
- Defining macros
- Mapping keys
- Setting abbreviations
[Back]
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
- (Left arrow) - Moves the cursor one character to the left.
- (Down arrow) - Moves the cursor down one line (it remains in the same column).
- (Up arrow) - Moves the cursor up one line (it remains in the same column).
- (Right arrow) - Moves the cursor one character to the right.
[Back]
Moving within a Line by Character Position
- \^ - Moves the cursor to the first nonblank character.
- 0 - Moves the cursor to the beginning of the line.
- $ - Moves the cursor to the end of the line.
- fx - Moves the cursor to the next x character.
- Fx - Moves the cursor to the last x character.
- tx - Moves the cursor to one column before the next x character.
- Tx - 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 opposite direction.
- Number| - Moves the cursor to the specified column.
[Back]
Moving to Words
- w - Moves the cursor to the next small word.
- b - Moves the cursor to the previous small word.
- e - Moves the cursor to the next end of a small word.
- W - Moves the cursor to the next big word.
- B - Moves the cursor to the previous big word.
- E - Moves the cursor to the next end of a big word.
[Back]
Moving by Line Position
- H - Moves the cursor to the top line on the screen.
- L - Moves the cursor to the last line on the screen.
- M - Moves the cursor to the middle line on the screen.
- + - Moves the cursor to the next line at its first nonblank character.
- - - Moves the cursor to the previous line at its first nonblank character.
- Enter - Moves the cursor to the next line at its first nonblank character.
[Back]
Moving to Sentences, Paragraphs, or Sections
- ( - Places the cursor at the beginning of the previous sentence.
- ) - Places the cursor at the beginning of the next sentence.
- { - Places the cursor at the beginning of the previous paragraph.
- } - Places the cursor at the beginning of the next paragraph.
- ]] - Places the cursor at the next section.
- [[ - Places the cursor at the previous section.
[Back]
Moving by Redrawing the Screen
- z - Redraws the screen with the current line at the top of the screen.
- z- - Redraws the screen with the current line at the bottom of the screen.
- z. - Redraws the screen with the current line at the center of the screen.
- /Pattern/z- - Redraws the screen with the line containing the character string, specified by the Pattern parameter, at the bottom.
[Back]
Paging and Scrolling
- Ctrl-U - Scrolls up one-half screen.
- Ctrl-D - Scrolls down one-half screen.
- Ctrl-F - Scrolls forward one screen.
- Ctrl-B - Scrolls backward one screen.
- Ctrl-E - Scrolls the window down one line.
- Ctrl-Y - Scrolls the window up one line.
- z+ - Pages up.
- z\^ - Pages down.
[Back]
Searching for Patterns
- [Number]G - Places the cursor at line number Number or at the last line if Number is not specified.
- /Pattern - Places the cursor at the next line containing the character string specified by the Pattern parameter.
- ?Pattern - Places the cursor at the next previous line containing the character string specified by the Pattern parameter.
- n - Repeats the last search for the specified Pattern in the same direction.
- N - Repeats the last search for the specified Pattern in the opposite direction.
- /Pattern/+Number - Places the cursor the specified number of lines after the line matching the character string specified by the Pattern parameter.
- ?Pattern?-Number - Places the cursor the specified number of lines before the line matching the character string specified by the Pattern parameter.
- % - Finds the parenthesis or brace that matches the one at current cursor position.
[Back]
Marking a Specific Location in a File and Returning
- " - Moves the cursor to the previous location of the current line.
- " - Moves the cursor to the beginning of the line containing the previous location of the current line.
- mx - Marks the current position with the letter specified by x.
- `x - Moves the cursor to the mark specified by x.
- 'x - Moves the cursor to the beginning of the line containing the mark specified by x.
[Back]
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!!
- aText - Inserts text specified by the Text parameter after the cursor.
- AText - Adds text specified by the Text parameter to the end of the line.
- iText - Inserts text specified by the Text parameter before the cursor.
- IText - Inserts text specified by the Text parameter before the first nonblank character in the line.
- o - Adds an empty line below the current line.
- O - Adds an empty line above the current line.
[Back]
Changing Text While in Input Mode
Use the following subcommands only while in text input mode.
They have different meanings in command mode.
- Ctrl-H - Erases the last character.
- Ctrl-W - Erases the last small word.
- \ - Quotes the erase and kill characters.
- Esc - Ends insertion and returns to command state.
- Ctrl-? - Interrupts and ends insert or Ctrl-D.
- Ctrl-D - Goes back to previous autoindent stop.
- \^ Ctrl-D - Ends autoindent for this line only.
- 0Ctrl-D - Moves cursor back to left margin.
- Ctrl-V - Enters any character.
[Back]
Changing Text from Command Mode
- C - Changes the rest of the line (same as c$).
- cc - Changes a line.
- cw - Changes a word.
- cwText - Changes a word to the text specified by the Text parameter.
- D - Deletes the rest of the line (same as d$).
- dd - Deletes a line.
- dw - Deletes a word.
- J - Joins lines.
- rx - Replaces the current character with the character specified by x.
- RText - Overwrites characters with the text specified by the Text parameter.
- s - Substitutes characters (same as cl).
- S - Substitutes lines (same as cc).
- u - Undoes the previous change.
- x - Deletes a character at the cursor.
- X - Deletes a character before the cursor (same as dh).
- << - Shifts one line to the left.
- >> - Shifts one line to the right.
- >L - Shifts all lines from the cursor to the end of the screen to the right.
- \~ - Changes letter at the cursor to the opposite case.
- ! - Indents for LISP.
[Back]
Copying and Moving Text
- p - Puts back text from the undo buffer after the cursor.
- P - Puts back text from the undo buffer before the cursor.
- "xp - Puts back text from the x buffer.
- "xd - Deletes text into the x buffer.
- y - Places the object that follows (for example, w for word) into the undo buffer.
- "xy - Places the object that follows into the x buffer, where x is any letter.
- Y - Places the line in the undo buffer.
[Back]
Restoring and Repeating Changes
- u - Undoes the last change.
- U - 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: This subcommand is not meant for use with a macro. Enter @@ to repeat a macro.
- "n p - Retrieves the nth last delete of a complete line or block of lines.
[Back]
Saving Changes to a File
- :w - Writes the edit buffer contents to the original file.
- :w File - Writes the edit buffer contents to the file specified by the File parameter.
- :w! File - Overwrites the file specified by the File parameter with the edit buffer contents.
[Back]
Editing a Second File
- :e File - Edits the specified file. If you are using this subcommand from the ex editor, you do not need to type the : (colon).
- :e! - Re-edits the current file and discards all changes.
- :e + File - Edits the specified file starting at the end.
- :e + Number File - Edits the specified file starting at the specified line number.
- :e # - Edits the alternate file. The alternate file is usually the previous file name before accessing another file with a :e command. However, if changes are pending on the current file when a new file is called, the new file becomes the alternate file. This subcommand is the same as the Ctrl-A subcommand.
- :r 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, you do not need to type the : (colon).
- :r !Command - Runs the specified AIX command and places its output into the file by adding new lines below the current cursor position.
- :ta Tag - Edits a file containing the Tag tag starting at the location of the tag. To use this command, you must first create a database of function names and their locations using the ctags command. If you are using this subcommand from the ex editor, you do not need to type the : (colon).
- Ctrl-A - 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. This subcommand is the same as the :e # subcommand.
[Back]
Editing a List of Files
- :n - Edits the next file in the list entered on the command line.
- :n Files - Specifies a new list of files to edit.
[Back]
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
- Ctrl-L - Clears and redraws the screen.
- Ctrl-R - Redraws the screen and eliminates blank lines marked with @.
- zNumber - Makes the window the specified number of lines long.
[Back]
Entering Shell Commands
The following subcommands allow you to run an AIX command within the vi editor.
.
- :sh - Enters the shell to allow you to run more than one AIX command. You can return to the editor by pressing the Ctrl-D key sequence.
- :!Command - Runs the specified AIX command and then returns to the editor.
Note: The # (alternate file), % (current file), and ! (previous command) special characters are expanded when following a :!. To prevent any of these characters from being expanded, use the \ (backslash).
- :!! - Repeats the last :!Command subcommand.
- Number!!Command - Runs the specified AIX command and replaces the lines specified by Number with the output of the command. If a number is not specified, the default value is 1. If the command expects standard input, the specified lines are used as input.
- !Object Command - Runs the specified AIX command and replaces the object specified by the Object parameter with the output of the command. If the command expects standard input, the specified object is used as input.
[Back]
Interrupting and Ending the vi Editor
- Q - Enters the ex editor in command mode.
- ZZ - Exits the vi editor, saving changes.
- :q - Quits the vi editor. If you have changed the contents of the editing buffer, the vi editor displays a warning message and doesnot quit.-
- :q! - Quits the vi editor, discarding the editing buffer.
- Esc - Ends text input or ends an incomplete subcommand.
- Ctrl-? - Interrupts a subcommand.
[Back]
Exit Status
The following exit values are returned:
- 0 - Indicates successful completion.
- >0 - Indicates an error occurred.
[Back]
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".