Using the vi editor This is a short guide to using vi, a full screen editor available in Unix. You can run vi in any window that emulates a VT100 terminal, including an xterm window. A nearly identical editor, vim, is available for PC's. ------------------------------------------ Invoking vi: vi enters vi (to edit the specified file) vi -r enters vi, recovers version of file most recently saved by the system in the case that vi had been abnormally aborted. ------------------------------------------ vi Modes: Command mode----allows you to move the cursor, delete text, move text, or enter either of the other two modes. This is the mode in force when you enter vi. Insert mode----allows you to insert characters. Last line mode---allows you to search for patterns, to write the file, or to exit without updating the file. Its name derives from the fact that, when in this mode, the cursor appears on the last line of the screen. ------------------------------------------ When in command mode: 1. Moving the cursor: use the arrow keys, or j down one line k up one line h left one position l right one position 25G (for example) go to line 25 CNTRL-f forward one "screen" CNTRL-b backward one "screen" 2. To enter insert mode: i insert at current location I insert at beginning of current line o make a new line below and insert there O make a new line above and insert there a insert following current location A insert at end of current line 3. To delete text: x delete current character X delete previous character dw delete to end of word dd delete current line 6dd (for example) delete the next 6 lines (including current one) 4. To move text: yy "yank" current line 4y (for example) to "yank" current line, plus next 4 lines p "put" (insert) most-recently "yanked" or deleted lines J append next line onto the end of current line 5. To enter last line mode : (a colon) 6. To "undo" most recent command: u (the letter) 7. To refresh screen (in case it gets garbled) CNTRL-L 8. To exit from vi and save file: ZZ ------------------------------------------ When in insert mode: ESC (escape key) return to command mode ------------------------------------------ When in last line mode: ESC (escape key) return to command mode r inserts contents of named file at cursor position w writes file (without leaving vi) w writes to named file (without leaving vi) w! overwrites to named file (without leaving vi) q quit (exit from) vi q! quit without updating file (since last write) / find next occurrence of the string ? find previous occurrence of the string