Here is a simple introduction to the vi editor. Once you are in the editor, or once you get going, there are many more things that you can do, but let's just go over the basics. 1. a. GETTING STARTED: vi filename When the editor cranks up, you will be at the top of the file. (NOTE: UNIX is case sensitive. The following are DIFFERENT filenames: dog Dog dOg doG DOg dOG DoG DOG b. GETTING OUT: :wq The colon (:) puts you on the command line. w writes the file and then q quits the editor. So wq is the command to write and quit. Both w and q can be issued as separate commands. What happens if changes have been made and you try to quit without writing? 2. MOVING AROUND IN THE FILE: a) Arrow Keys: Unfortunately, most arrow keys DO NOT WORK as they are different on every terminal. the vi editor has its own "arrow keys": h=left j=down k=up l=right. Your four fingers over these keys will let you get almost anywhere, if slowly. b) Getting to a specific line: type the line number then G (the capital letter G). you will move to that line. Capital G all by itself moves to the bottom of the file. c) Where am I? cntl-g will report the line number and file name. d) Page forward: cntl-f e) Page backward: cntl-b f) Top of file: Using the method of 2.b above, 1G g) Beginning of Next word: w <---------| | h) End of next word: e | | these all may be i) Beginning of previous word: b | preceded by a number | for multiple moves j) End of line: $ | | k) Beginning of line: 0 | | l) First non-blank of current line: ^ <------- 3. SEARCHING FOR A STRING: Hitting the / key will begin a search for whatever string you type next. A carriage return initiates the search. / searches forward from the current cursor position, and cycles through to the top of the file. Hitting the ? key also initiates a search, but this search looks backward through the file. Having found any occurrence of the string, hitting lower case n will get the next occurrence in the same search direction, and upper case N will get the next occurrence in the opposite search direction. If you need to search for certain special characters, / for instance, precede the special character with a backslash \ and all will be fine. 4. ADDING OR INSERTING TEXT: vi has a command mode and an insert mode. Insert mode is entered in different way, depending on WHERE in the file you want to start inserting. Again, the are all case-sensitive. NOTE: to END insert mode, hit the ESC. a) Insert starting before the cursor: i (lower case) b) Insert starting before current line: I (upper case) c) Insert starting after the cursor: a (lower case) d) Insert starting after current line: A (upper case) e) Open a new line, inserting after current line: o (lower case) f) Open a new line, inserting before current line: O (upper case) 5. GETTING RID OF STUFF: characters, words, lines, groups of lines may be easily disposed of in different ways. NOTE: the deletion may be UNDONE by typing u (lower case). Upper case U will undo multiple changes to a single line. a) delete from cursor to end of line: D (upper case) b) delete charcter under cursor: x (lower case) c) delete character before cursor: X (upper case) d) delete from cursor to end of word: dw (lower case) e) delete entire current line: dd (lower case) b-e above may be repeated by preceding them with a number. 6. CHANGING OR REPLACING THINGS: Text may be changed or replaced in various ways, too. Again, knowing the any change can be undone (u) or lots of changes on one line can be Undone (U) is comforting from the start. a) replace cursor with single character: r (then the character) NOTE: to exit the replace or change mode for the following, type ESC. b) Start replacing with current character, keep going: R (uppercase) e) change entire line: cc (line disappears and insert mode begins) f) change from cursor to end of line: c$ (note that a $ will mark the extent of the change) c) change word: cw [change from cursor to end of word] (note that a $ will mark the extent of the change) d) change letter: cl (note that a $ will mark the extent of the change) Again, miltiple instances of these command can be achieved by preceding them with a number.