When you edit a file, vi makes a copy of the file to a memory buffer. This way, if any unwanted changes are made, the original file is not destroyed. When your work is completeed, you must remeber to save the buffer which contains your changes. The visual editor has two modes of operation: text input mode and command mode.
vi [-l] [-R] [+n | +/pattern] [filename]where filename is the name of the file to be edited or created, n is the line number on which to start the display, and pattern is a string specifying which line on which to start. You will then be placed in command mode. The -l option tells vi to create indents appropriate for LISP code. Passing the -R option tells vi to open the file read-only -- the same as if the view command was used.
When editing a file, vi places a tilde (~) as the first character of lines past the end of your file. These lines are not part of your file, and are for display purposes only.
Key Action Key Action ------------------------------------------------------------------------------- h or [Left Arrow] Left one character l or [Right Arrow] Right one character j or [Down Arrow] Down one line k or [Up Arrow] Up one character ^ 1st character on current line $ End of current line 0 1st position of current line G Last line of the file + 1st character of next line :n Line n of the file - 1st character of previous line H Top line of screen nH n lines after top line M Middle line of screen nL n lines before last line L Last line of screen B Back one word (ignore punctuation) b Back one word E End of next word (ignore punctuation) e End of next word W Start of next word (ignore punctuation) w Start of next word ( Beginning of previous sentence ) Beginning of next sentence [[ Back one section ]] Forward one section { Beginning of previous paragraph } Beginning of next paragraph [CTRL][B] Scroll back one screen [CTRL][F] Scroll forward one screen [CTRL][U] Scroll back half screen [CTRL][D] Scroll forward half screen [CTRL][E] Scroll up one line [CTRL][Y] Scroll down one line
Key Action Key Action ------------------------------------------------------------------------------- a Insert after cursor A Append to end of line i Insert before cursor I Insert at beginning of line o Insert line below cursor O Insert one line above cursor [CTRL][J] Move down one line [CTRL][W] Move back one word [ENTER] Add a new line [Backspace] Move back one character kill Delete line (set by stty) [CTRL][H] Move back one character [CTRL][I] Insert a tab [CTRL][T] Move to next tab setting [ESC] Returns to command mode [CTRL][V] Quote next character
Key Action Key Action ------------------------------------------------------------------------- cw Change word cc Change line C Change text from current cl change character right of cursor position to end of line . Repeat last change dd Delete current line ndd Delete n lines D Delete remainder of line dw Delete a word d} Delete to next paragraph d^ Delete back to beginning of line dh Delete char left d/pattern Delete up to pattern dn Delete up to pattern dL Delete up to last line on screen dfa Delete up to and dta Delete up to a including a dG Delete to end of file ~ Reverse case p Inserts last deleted text P Inserts last deleted text before cursor after cursor rx Replaces character with x Rtext Replaces text beginning at cursor s Substitute character S Substitute entire line x Delete current cursor position X Delete back one character
Pressing Y or yy will copy the current line to the buffer. The y]] command will copy the text up to the next section heading. You can also copy to the end of a word by using the ye command.
The vi editor also provides a series of numbered buffers that you can use for storing multiple selections of text. To use these buffers, type a " followed by the buffer number before the yy, d, or p commands. This will respectively yank the current line, delete the character, and put the contents of the specified buffer into the file. Since buffer one is used by vi for normal deletion, you may wish to use a safer buffer when moving or copying text. This can be done by using a lower case letter as the buffer number. As an example, to yank the next 3 lines of text and place them in buffer r you would type:
"r3yy
If you are programming in LISP or writing equations, you may find it useful to match your parenthesis and brackets. This can be done in vi by use of the % command. This command will find the match for the current brace, bracket, or parenthesis.
You can also search for a text string by placing a / in front of the text for which you are searching. The vi editor will then place the cursor at the first location after the cursor of the specified text. To search backwards from the cursor, use the ? instead of a /. You can repeat the previous search by pressing n, repeat the search in the opposite direction with the N command, repeat the forward search with the / command, and using ? will repeat the previous backwards search command.
Aligning Text You can tell vi to shift your text 8 spaces to the right or left by use of the > > and < < commands respectively. If you wish to shift your text from the current line to the end of the screen, use the > L and < L commands. You can also join two lines by using the J command. This command will place the next line at the end of the current line, wrapping the text to the next line as necessary. If you want to break up a line into two or more lines, place the cursor at the position where the line is to be broken, and insert a carriage return ([ENTER]).
:3,25w partial.filewill save lines 3 through 25 to the partial.file file.
If you want to save your work and exit the editor, you can do that by issuing the ZZ or the :wq command. If you wish to quit vi without saving and you have not made any changes to the file, you can use the :q command. If you have made changes to the file, but you wish to exit vi without saving them, use the :q! command.
You can make a list of files to edit by placing each filename after the :n command. To edit the next file in the list, issue the :n command.
You can issue AIX commands from within vi by typing :! followed by the command.
You can create a subshell by issuing the :sh command. When you are done, press [CTRL] [D] or type EXIT [ENTER] to return to vi.
You can move the cursor to a specific column by specifying the column number and then the vertical bar ( | ) character.
You can set the column position for vi to wrap the text by setting the wrap margin variable. For example, to set the warp at column 65 you would enter the command :set wm=15 where 15 is 80 - desired column position.
Because vi is a standard AIX application, many bookstores will carry computer books which discuss the use of vi as well as AIX.
The UCF library contains many books on the UNIX operating system. Most of these books can be found in the QA76 section of the library.
(c) Copyright UCF Computer Services I& R Support 07/26/93