Introduction to vi -- nerd 91.10.23 Vi (pronounced 'vee eye') is a moded editor. This means that it has several modes of operation. The three principle modes are text entry, command mode, and command line. When vi is first started it is in command mode. In command mode the keys you type are not inserted into your file, rather they instruct vi do do things. Here we will only deal with the most basic functions available. They are; motion commands: h -- move the cursor left one space j -- move the cursor down one line k -- move the cursor up one line l -- move the cursor right one space $ -- move cursor to the end of line 0 -- move cursor to the beginning of line ^f -- forward a page ^b -- back a page H -- top of page L -- bottom of page mode commands (these commands leave you in text entry mode): a -- append text i -- insert text A -- append text at end of line I -- insert text at beginning of line o -- open a line below and insert text O -- open a line above and insert text other commands: u -- undo last change x -- delete current character (the one under the cursor) f -- find character forward in line F -- find character backward in line ; -- repeat last find character / -- search for text forward ? -- search for text backward n -- repeat last search N -- repeat last search in opposite direction : -- command line G -- go to line r -- replace character R -- replace to end of line c -- change C -- change to end of line d -- delete D -- delete to end of line ~ -- change case of character . -- repeat last command ^g -- where am I? Most of these commands can be prefixed by a count in which case they get repeated count times. For example typing "5l" will move the cursor 5 spaces to the right, "10x" will erase 10 characters starting with the one under the cursor. Some commands are very limited without a count, for example 'G' will go to the last line of the file if no count is given, to go to the first line of a file you would type "1G" and you would type "35G" to go to the 35th line of the file. The mode commands will silently ignore a count. Some of these commands require more than just one letter. When you type "d" the editor just sits there waiting. "d" needs to be followed by a range. "dw" will delete a word, "d$" will delete to the end of line, "d0" deletes to the beginning of a line, "dd" deletes the whole line. "c" works the same way, you can change a word with "cw", "c0" will change to the beginning of a line, "c$" will change to the end of line, and "cc" will change the whole line. Other commands take a single character as a parameter, "f" needs to know what character to search for. "fx" will find the next occurance of the character "x" on the current line, "rx" will replace the current character with an "x". Some commands need to be followed by more than a single character, for example "/" and "?" could search for a word or a phrase. They will move the cursor to the last line of the display and prompt for the search pattern. In text entry mode each character you type is inserted in your file at the point the cursor is at. Exceptions are backspace, "\", and escape. The backspace will backup a character and erase it, the escape key gets you out of text input mode and into command mode. The "\" key allows you to enter control codes directly into your text. You type "\" followed by the control character and the control character replaces both. If the character that follows the "\" is not a control character the "\" looses its special meaning. Command line mode gives you access to all the remaining functionality of vi. This is how you do search and replaces, file manipulation, shell escapes, macro definitions, and more. For now we are only concerned with a few command line commands. They are; q -- quit q! -- quit damn it w -- write a file w! -- write damn it r -- read a file shell -- start a shell to give operating system commands. On the most basic level, after having edited a file using the command and text input modes you would type ":" to get to command line mode and then "wq" to write and quit. If your changes are extensive and you fear loosing them to a system crash or some other occurance you can type ":w" every now and then to update the file with your changes. If you try to quit while there are changes that have not been saved to disk vi will tell you about it and return you to command mode. You can override vi's protests with the "damn it" parameter, type "q!" instead of just "q".