Other references: man vi hints->vi.quickref.alphabetical =================================== Vi is an extremely complicated and powerful editor. It has more commands than most people can either remember or use. The best approach is to learn a small set of commands that are necessary for use, and then slowly pick up other keys that you find speed up your work. Selecting the keys in your vi 'vocabulary' is a very personal thing. I have categorized the keys into several separate functional groups. As I get more time, I will try to organize these groups so that the first one or two keys in each group will be all you need to get started. Most important in vi is to remember that there are several distinctly different modes. ESCAPE always brings you back to command mode, from which most of these keys can be typed. You can be sure you are in command mode by hitting escape, even if you are already in command mode. Also, there are several groups of keys that do similar things. For example, there is a set of keys that puts you into other modes from command mode. (It is a good habit to get use to hitting escape after you are finished with a particular mode so that vi is in the command state when you finish that change.) CLASSES OF VI COMMANDS movement These move the cursor in various ways. All movement keys can be combined with operation keys to causes the key to operate on the range of text between where the cursor was, and where the cursor ends up. operation These affect a range of the text in some way. insert There are about 5 different ways you can enter insert mode. Most of these involve different positions to insert at which to start inserting. simple action These all involve simple single character changes to the text. repeat keys These repeat previous commands. The operation keys must be followed by a movement key, unless they are doubled. For instance, the w movement key advances a single word. The d key deletes (you have to tell how much to delete with a movement key.) dw will delete a word. Doubled operation keys affect a line. For instance, dd will delete a line. Also, you can specify a count with these actions. For instance, 2w will move forward 2 words, d2w will delete 2 words, and 2dd will delete two lines. The commands preceded by an * are more important and probably should be learned first. * ^[ Escape cancels a pending command in command mode, and terminates insert mode. Movement keys * h Move left one column. * j Move down one line. * k Move up one line. * l Move right one column. ^B Backward one screen. ^D Scroll the window down one half screen. ^E Scroll the screen up one line. ^F Forward one screen. ^H (BS) Moves cursor left one space in command mode. In insert mode, erases the last character typed. ^J Move the cursor down one line. ^M (CR) Move to the first non-white character in the next line. In insert mode, a carriage return opens a new line for input. ^N Move the cursor down a line. ^P Move the cursor up a line. ^U Scroll the window up one half screen. ^Y Scroll the screen down one line. SPACE Move the cursor right on column. $ Move to the end of the current line. % If the cursor rests on a paren '()', brace '{}', or bracket '[]', move to the matching one. + Same as carriage return, in command mode. , Reverse of the last t, T, f, or F command. - Move to the first non-white character in the previous line. 0 Move to the start of the current line. Also used within counts. w Move forward one word. b Back one word. e Move to the end of a word. B Backward one blank-delimited word. E End of the end of a blank-delimited word. W Move forward one blank-delimited word. F Find a character backward on the current line. T Reverse search 'upto' the given character. G Go to the given line number (end of file, by default). H Move to the first non-white char. on the top screen line. M Move to the first non-white char. on the middle screen line. L Move to the first non-white char. on the bottom screen line. [[ Move backward one C function. ]] Move forward one C function. ^ Move to the first non-white on the current line. f Find a character on the current line. t Move forward 'upto' the given character on the current line. | Move to the column given by the preceding count. Operation keys * d The delete operator. c The change operator. < The 'left shift' operator. (see autoindent, shiftwidth) > The 'right shift' operator. y The yank operator. Y Yank the current line. Same as 'yy'. Insert keys * i Insert text before the cursor. I Insert before the first non-white char. on the current line. a Append text after the cursor. * A Append at the end of the current line. * o Open a new line below the current line, and start inserting. O Open a new line above the current line, and start inserting. C Change the rest of the current line. Same as 'DA'. repeat keys * . Repeat the last edit command. ; Repeat last t, T, f, or F command. n Repeat the last string search. N Reverse the last string search. simple action D Delete the rest of the current line. J Join two lines. P Put the yank/delete buffer before the current cursor position. * x Delete the character under the cursor. X Delete one character before the cursor. * ZZ Exit from the editor, saving changes if necessary. * u Undo the last edit. p Put the yank/delete buffer after the cursor. s Replace characters. r Replace a character. m Set a mark at the current position (e.g. ma or mb). z Redraw the screen with the current line at the top (zRETURN), the middle (z.), or the bottom (z-). * ^L Clear and redraw the screen. ^G Same as ":f" command. Displays file information. ^] Moves to the tag whose name is given by the word in which the cursor resides. ' Used to move the cursor to a previously marked position, as in 'a or 'b. The cursor moves to the start of the marked line. The special mark '' refers to the "previous context". ` Move to the given mark, as with '. The distinction between the two commands is important when used with operators. / Start of a forward string search command. String searches may be optionally terminated with a closing slash. To search for a slash use '\/' in the search string. ? Same as '/', but search backward. 1-9 Used to add 'count' prefixes to commands. : Prefix character for "ex" commands.