vi or vedit Command Purpose Edits files with a full-screen display. Syntax { vi | vedit } [ -c Subcommand ] [ -l ] [ -R ] [ -tTag ] [ -v ] [ -wNumber] [ -yNumber ] [ -r [ File ] ] [ + [ Subcommand ] ] [ File ... ] Description The vi command starts a full-screen editor based on the underly- ing ex editor. Therefore, ex subcommands can be used within the vi editor. The vedit command starts a version of the vi editor intended for beginners. In the vedit editor, the report option is set to 1, the showmode option is set, and the novice option is set, making it a line editor. You start the vi editor by specifying the name of the file or files to be edited. If you supply more than one File on the com- mand line, the vi editor edits each file in the specified order. 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. vi Editor Limitations The following list provides the maximum limits of the vi editor. These counts assume single-byte characters. * 2048 characters per line * 256 characters per global command list * 128 characters in the previously inserted and deleted text * 128 characters in a shell escape command * 128 characters in a string-valued option * 30 characters in a tag name * 1,048,560 lines of 2048 characters per line silently enforced Note: Running vi on a file larger than 64 megabytes may cause the following error message to display: 0602-103 file too large to place in /tmp * 128 map macros with 2048 characters total. vi Editing Modes The vi editor operates in the following modes: 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 can- cel a partial subcommand. text input mode You use the vi editor in this mode when you add text. Enter text input mode with any of the following subcom- mands: the a subcommand, A subcommand, i subcommand, I sub- command, o subcommand, O subcommand, cx subcommands (where x represents the scope of the subcommand), C subcommand, s sub- command, 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. 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 (the Ctrl-C key sequence) 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 mean- ing is given to the following characters when they are used be- fore commands that specify counts: % All lines regardless of cursor position $ Last line . Current line Customizing the vi Editor You can customize the vi editor by: * Setting editor options * Defining macros * Mapping keys * Setting abbreviations 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. 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. -l Enters the vi editor in LISP mode. In this mode, the vi edi- tor creates indents appropriate for LISP code, and the (, ), {, }, [[, and ]] subcommands are modified to act appropriately for LISP. -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 overwrit- ing. -tTag Edits the file containing the Tag and positions the editor at its definition. To use this flag, you must first create a da- tabase 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. 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 ex- tent 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). 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 se- quence. Moving within a File The subcommands for moving within a file enable you to move in the following ways: * 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. Editing a File with the vi Editor The subcommands for editing enable you to perform the following tasks: * Adding Text to a File * Changing Text While in Input Mode * Changing Text from Command Mode * Copying and Moving Text * Restoring and Repeating Changes. Manipulating Files with the vi Editor The subcommands for manipulating files allow you to do the tasks outlined in the following sections: * Saving Changes to a File * Editing a Second File * Editing a List of Files * Finding Out File Information. General Subcommands The vi editor provides the subcommands described in the following sections: * Adjusting the Screen * Entering Shell Commands * Interrupting and Ending the vi Editor. Moving within a Line Enter the following subcommands in command mode. You can cancel an incomplete command by pressing the Esc key. If you need in- formation about the format of vi subcommands, see "vi General Subcommand Syntax". (Left arrow) or h or Ctrl-H Moves the cursor one character to the left. (Down arrow) or j or Ctrl-J or Ctrl-N Moves the cursor down one line (it remains in the same column). (Up arrow) or k or Ctrl-P Moves the cursor up one line (it remains in the same column). (Right arrow) or l Moves the cursor one character to the right. Moving within a Line by Character Position Enter the following subcommands in command mode. You can cancel an incomplete command by pressing the Esc key. If you need in- formation about the format of vi subcommands, see "vi General Subcommand Syntax". \^ 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. Moving to Words Enter the following subcommands in command mode. If you need information about the format of vi subcommands, see "vi General Subcommand Syntax". 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. Moving by Line Position Enter the following subcommands in command mode. If you need information about the format of vi subcommands, see "vi General Subcommand Syntax". 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 charac- ter. - 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. Moving to Sentences, Paragraphs, or Sections Enter the following subcommands in command mode. You can cancel an incomplete subcommand by pressing the Esc key. If you need information about the format of vi subcommands, see "vi General Subcommand Syntax". ( 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. ]] 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. Moving by Redrawing the Screen Enter the following subcommands in command mode. You can cancel an incomplete subcommand by pressing the Esc key. If you need information about the format of vi subcommands, see "vi General Subcommand Syntax". 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 char- acter string, specified by the Pattern parameter, at the bottom. Paging and Scrolling Enter the following subcommands in command mode. You can cancel an incomplete subcommand by pressing the Esc key. If you need information about the format of vi subcommands, see "vi General Subcommand Syntax". 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. Searching for Patterns Enter the following subcommands in command mode. You can cancel an incomplete subcommand by pressing the Esc key. If you need information about the format of vi subcommands, see "vi General Subcommand Syntax". [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 char- acter 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 oppo- site 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. Marking a Specific Location in a File and Returning Enter the following subcommands in command mode. You can cancel an incomplete subcommand by pressing the Esc key. If you need information about the format of vi subcommands, see "vi General Subcommand Syntax". " 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. Adding Text to a File (Text Input Mode) Enter the following subcommands in command mode to change the vi editor into text input mode. If you need information about the format of vi subcommands, see "vi General Subcommand Syntax". aText Inserts text specified by the Text parameter after the cur- sor. End text input mode by pressing the Esc key. AText Adds text specified by the Text parameter to the end of the line. End text input mode by pressing the Esc key. iText Inserts text specified by the Text parameter before the cursor. End text input mode by pressing the Esc key. IText Inserts text specified by the Text parameter before the first nonblank character in the line. End text input mode by pressing the Esc key. o Adds an empty line below the current line. End text input mode by pressing the Esc key. O Adds an empty line above the current line. 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. If you need infor- mation about the format of vi subcommands, see "vi General Sub- command Syntax". 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. Changing Text from Command Mode Use the following subcommands in command mode. An incomplete subcommand can be canceled by pressing the Esc key. If you need information about the format of vi subcommands, see "vi General Subcommand Syntax". 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 parame- ter. 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. Copying and Moving Text Use the following subcommands in command mode. An incomplete subcommand can be canceled by pressing the Esc key. If you need information about the format of vi subcommands, see "vi General Subcommand Syntax". 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. Restoring and Repeating Changes Use the following subcommands in command mode. An incomplete subcommand can be canceled by pressing the Esc key. If you need information about the format of vi subcommands, see "vi General Subcommand Syntax". 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. Saving Changes to a File Use the following subcommands in command mode. If you need in- formation about the format of vi subcommands, see "vi General Subcommand Syntax". :w Writes the edit buffer contents to the original file. If you are using this subcommand within the ex editor, you do not need to type the : (colon). :w File Writes the edit buffer contents to the file specified by the File parameter. If you are using this subcommand within the ex editor, you do not need to type the : (colon). :w! File Overwrites the file specified by the File parameter with the edit buffer contents. If you are using this subcommand within the ex editor, you do not need to type the : (colon). Editing a Second File Enter the following subcommands in command mode. If you need information about the format of vi subcommands, see "vi General Subcommand Syntax". :e File Edits the specified file. If you are using this subcom- mand 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 speci- fied 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 posi- tion. :ta Tag Edits a file containing the Tag tag starting at the loca- tion of the tag. To use this command, you must first create a da- tabase 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 be- comes the alternate file. This subcommand is the same as the :e # subcommand. Editing a List of Files Enter the following subcommands in command mode. If you need information about the format of vi subcommands, see "vi General Subcommand Syntax". :n Edits the next file in the list entered on the command line. If you are using this subcommand from the ex editor, a : (colon) is not needed. :n Files Specifies a new list of files to edit. If you are using this subcommand from the ex editor, a : (colon) is not needed. Finding Out File Information Enter the following subcommand in command mode. If you need in- formation about the format of vi subcommands, see "vi General Subcommand Syntax". 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. Adjusting the Screen Enter the following subcommands in command mode. An incomplete subcommand can be canceled by pressing the Esc key. If you need information about the format of vi subcommands, see "vi General Subcommand Syntax". 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. Entering Shell Commands The following subcommands allow you to run an AIX command within the vi editor. Enter these subcommands in command mode. If you need information about the format of vi subcommands, see "vi General Subcommand Syntax". :sh Enters the shell to allow you to run more than one AIX com- mand. You can return to the editor by pressing the Ctrl-D key sequence. If you are using this subcommand within the ex edi- tor, a : (colon) is not needed. :!Command Runs the specified AIX command and then returns to the editor. If you are using this subcommand within the ex editor, a : (colon) is not needed. 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. Interrupting and Ending the vi Editor Enter the following subcommands in command mode. If you need information about the format of vi subcommands, see "vi General Subcommand Syntax". 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 does not quit. If you are using this subcommand from the ex editor, a : (colon) is not needed. :q! Quits the vi editor, discarding the editing buffer. If you are using this subcommand from the ex editor, a : (colon) is not needed. Esc Ends text input or ends an incomplete subcommand. Ctrl-? Interrupts a subcommand. Exit Status The following exit values are returned: 0 Indicates successful completion. >0 Indicates an error occurred. 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 Pro- cedures introduces general concepts about editors and describes the main AIX editors. Understanding Modes and Subcommands in the vi Editor in AIX Ver- sion 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.