QUICK INTRODUCTION TO THE vi VIDEO EDITOR T.C. Slattery, US Naval Academy ENTERING vi vi name start vi editor with file name . The file is created if it doesn't exist. LEAVING vi ZZ exit from vi, saving changes. :wq exit from vi, saving changes. :q! exit from vi, discarding changes. CURSOR POSITIONING h moves left one character position. j moves down one line. k moves up one line. l moves right one character position. 0 (zero) moves to the beginning of a line. w moves right one word. b moves left one word. CTRL-u moves up 1/2 screen full. CTRL-d moves down 1/2 screen full. G moves to the bottom of the file. nG moves to line number n . CTRL-l (ell) clear screen and re-draw. NOTES: ESC represents the ESC key. Press the ESC key when it is called for in the following commands. CTRL- represents the CTRL key. Hold the CTRL key and press the following key simultaneously. CR represents the ENTER (also called RETURN) key. TEXT MODIFICATION itextESC inserts text to the left of the cursor. Insert doesn't cause the cursor to move; text appears as it is typed, terminate with ESC. atextESC appends (inserts) text to the right of the cursor, terminate with ESC. otextESC opens a new line below the one the cursor is currently in and puts text there, terminate with ESC. OtextESC opens a new line above the one the cursor is currently in and puts text there, terminate with ESC. RtextESC Replaces (overprints) characters at the cursor position, terminate with ESC. dd deletes the line the cursor is on. ndd deletes n lines from the cursor position. NOTE: Deleted lines are replaced with the character @ (which is removed when the page is re-drawn) when using vi over slow modem connections. D deletes characters from the cursor position to the end of the line. x deletes the character at the cursor. nx deletes n characters to the right of the cursor. u undo the last change. PATTERN SEARCHING /patCR positions the cursor at the next occurrence of the string pat (follow the pattern with hitting the enter, that is carriage return, key). --------SECOND LEVEL vi EDITING COMMANDS------------------- CURSOR POSITIONING } move down one paragraph. { move up one paragraph. mx save the current cursor position and label it with the letter x. (x is any letter) 'x return to the cursor position labeled x. TEXT MODIFICATION dw delete the next word. . (period) repeat last change. A append at the end of the current line. P put back deleted line(s). Text deleted with D and dd commands may be pasted back with the P command. Text is pasted in before the cursor position. :a,bs/old/newCR From line number 'a' to line number 'b', substitute the pattern 'old' with the pattern 'new'. You may use any text string which doesn't contain a carriage return in place of the 'old' and 'new' strings. Use CTRL-G to tell what line the cursor is on (after typing the new string, hit the enter key). PATTERN SEARCHING /CR search for the next occurrence of a previously specified search string (type the slash key then the enter, i.e. carriage return, key). MISCELLANEOUS :wCR write out current changes. The vi editor works on a copy of your file. The :w command causes the editor to write its copy over the original which is on the disk (type the colon then the w and then the enter key). :w nameCR write out changes to the file name . This is like the :w command but the changes are written into the file you specify. (good for making intermediate copies) Cut and Paste Move to the beginning of the text to cut. Use dd to delete (cut) several lines. Use D to cut only the end of one line. Move to the place where you wish to paste the text. Use P to put back the text. You may need to clean up the spacing after pasting.