Information from http://ecn.www.ecn.purdue.edu/ECN/Documents/VI/ Command line: vi or vi : is used to start many commands. :w writes to the current file :w writes to a different file :q quits :quit! quits without saving VI starts in command mode, giving these options, some with (shortcuts): append (a, A) insert (i, I) open (o, O) change (c, C) replace (R) these all go to text input mode, from which you return with Esc. Other command mode options: join (J) -- like pico's ^J command delete undo (u, U) move cursor yank (y, Y) and put (p, P) replace (r) named buffers Ctrl-D moves _downward 1/2 screen Ctrl-U moves _upward 1/2 screen Ctrl-B moves _backward 1 screen Ctrl-F moves _forward 1 screen Goto: G (capitalized) or G . So G or 250G . 250G moves to the beginning of line 250 if it exists, otherwise nothing. G moves to the end of the file. Ctrl-g (lowercase) prints status info on the file and your position. Search: / -- like the first part of a Perl regexp. Search down. ? -- same, but searches upward. n finds the _next occurrence N finds the _Next occurrence in the other direction Positioning on screen: H - moves to the _Highest line on screen M - moves to the _Middle line on screen L - moves to the _Lowest line on screen 3H moves to the 3rd line from the highest 4L moves to the 4th line from the lowest Arrow keys work for character movement, as do h - left j - down k - up l - right return moves down a line and goes to the beginning Movement scope 0 moves to the beginning of the line $ moves to the end of line w, W move to the beginning of the next word on the right b, B move to the beginning of the next word on the left e, E move to the end of the word on the right or the current word all these can be preceded with numbers of times to do it the lower-case variations include punctuation as words; upper-case do not. Editing text If you forget which mode you're in, press Esc. If command, terminal beep. If input, move to command. append mode comes in two forms: a and A. a moves one character to the right and enters input mode A moves to the end of the line and enters input mode note that the screen isn't necessarily redrawn in append mode as you type insert mode comes in two forms: i and I. i inserts text to the left of the cursor. I moves to the line beginning and inserts text. open mode comes in two forms: o and O. o opens a blank line below the current line O opens a blank line above the current line :r reads another file into the current buffer directly below the current line. deleting text is in two forms: D as a command, and d as an operator D removes the text on the current line from the cursor to the end of line dw deletes a word (forward) db deletes a word _backward d$ deletes from cursor to eol (like D) d0 deletes from cursor to beginning of line dL deletes from current line to end of screen ("delete Lines") dG deletes from current line to end of file ("delete Global") d) deletes complete sentence forward d( deletes complete sentence backward dd deletes a complete line ("delete delete") Note that all these can be preceded with numbers, as they are operator-scope pairs. When deleting, an @ symbol replaces deleted lines to save processor redraws. Ctrl-R or Ctrl-L redraws the screen. change text mode comes in two forms: C (command) and c (operator) cw changes a word (forward) cb changes a word _backward c$ changes from cursor to eol (same as C) c0 changes from cursor to beginning of line cL changes from current line to end of screen ("change Lines") cG changes from current line to end of file ("change Global") c) changes from cursor to sentence start c( changes from cursor to sentence end cc changes complete lines These basically act as overwrite filters to keep you from changing more than you want to change. replace comes in two forms: r and R r replaces a single character you key in, staying in command mode R replaces characters as you key them, going in text input mode Note that R only replaces until the end of the current line, but continues inputting after that, so you can add any number of new lines erase ("gobble") comes in two forms: x and X X erases the character to the left of the cursor x erases the character the cursor is sitting on. Be very careful of using erase to get rid of lots of text, as the redraws don't happen as frequently as the erase commands. xp transposes pairs of characters Undo comes in two flavors: u and U u undoes the most recent command U undoes all the changes to the current line Yanking (copying) text comes in two forms: y (operator) and Y (command) Y copies a whole line y behaves like erase and change and move Putting (pasting) has two forms: p and P p pastes after the cursor P pastes before it Thus xp is really just erase a character and then paste it to the right. Cut and paste is done via delete and then paste. Note that if you delete more after the original deletion, the old buffer does not get restored. Named buffers: 26 buffers [a-z] can be used to hold temporary text access them by "acommand lowercase name overwrites the buffer; uppercase appends "a7dd delete seven lines and overwrite them to buffer a "G2yy yank two lines and append them to buffer g Beware of the fact that there isn't an easy way to access the contents of a named buffer without going and just pasting and undoing their contents. paste from a named buffer like so "gp or "gP - paste g below or above the current line Viewing line numbers: :set number :set nonu to get rid of it. Note that these are much prettier in vi than in vim. the Ex editor Line editor rather than screen editor. Use commands by prefacing them with : in command mode i.e. :wq get into Ex by typing :Q and then typing vi at the ex prompt when you want to come back. Repeating commands Repeat them by typing . in command mode. Do search and replace with, for example, /HAE cw Hollis Easter n . n . etc.. To use a shell program: :w -- write your buffer, for good measure. :! -- get to a shell prompt Open multiple files with :e for Edit :e!\ newfile -- tosses buffer, doesn't update, gets newfile :e\ # More useful cutting and pasting ma -- _mark this point with name a move to a new place further on y'a -- yank from mark a to here -- can be used with other operators, too