vi is the standard unix text editor - it is available on almost every
unix system you can find.  vi has two distinct modes - edit and insert.
In edit mode, you can move around the text, cut, copy and paste lines,
delete text, etc.  In insert mode, you can actually type text into your
document.

This is a quick reference to the most common vi commands - it's by a
Caltech sysadmin (rem@cco.caltech.edu) and it's what I used to look stuff
up when I was a frosh and just learning unix.



     _________________________________________________________________

ITS Reference Guides

                        VI Text Editor Reference Sheet
     _________________________________________________________________
   
Roger Murray

October 19, 1994
     _________________________________________________________________
   
Contents:

     * Entering vi
     * Movement
     * Inserting Text
     * Deleting Text
     * Other Commands
     * Saving and Exiting vi
     * Some vi Settings
       
                                  Entering vi
                                       
vi file        Open file for editing.
vi +n file     Open file and go to line n.
vi -r file     Recover a failed editing session.

                                   Movement
                                       
            backward    forward
 character     h           l
      line     k           j
      word     b           w
  sentence     (           )
 paragraph     {           }
1/2 screen   CTRL-U     CTRL-D
  1 screen   CTRL-B     CTRL-F

   The above commands can be prefaced by a number to indicate a desired
   repetition. For example, the command 5w moves the cursor five words to
   the right and the command 10k moves the cursor ten lines up.
   
0      Go to beginning of the current line.
$      Go to end of the current line.
nG     Go to line n.  (Default = last line)

                                Inserting Text
                                       
i               inserts text before the cursor.
a               appends text after the cursor.
A               appends text at the end of a line.
o               opens a new (blank) line below the cursor and enters insert mod
e.
O               opens a new (blank) line at the cursor and enters insert mode.
:r filename     inserts the contents of filename at the current line.

   Pressing  will exit insert mode.
   
                                 Deleting Text
                                       
x      deletes the character at the cursor.
dw     deletes the current word.
dd     deletes the current line.

   As with the movement commands, these commands can be prefaced by a
   number to indicate a desired repetition. The command 3dw deletes the
   next three words, for example.
   
                                Other Commands
                                       
           redraws the screen.
.                   re-does the last command.
u                   undoes the last command that changed the buffer.
/string             searches for string.
n                   searches for the next occurrence of string.
N                   searches for the previous occurrence of string.
:s/from/to          replaces to for one from on one line.
:s/from/to/g        replaces to for every from on one line.
:%s/from/to/g       replaces to for every from on every line.
nY                  yanks a copy of the next n lines. (Default = 1)
P                   puts yanked or deleted line(s) at the current line.
p                   puts yanked or deleted line(s) after the current line.
rX                  replaces character at cursor with X
R                   begin replacing text at cursor (press  when finished).

                             Saving and Exiting vi
                                       
   The following is a list of saving and exiting commands. Each has its
   advantages and disadvantages. Decide which ones appeal to you and use
   them.
   
:w     save (don't quit)  [:w filename saves to filename]
:q     save and quit
:q!    quit (don't save)
:x     save if a change has been made, quit regardless
ZZ     same as :x

                               Some vi Settings
                                       
:set auto-indent       Automatically indent at the same level as the line above.
:set number           Display line numbers.
:set showmode         Indicate if vi is in insert mode.
:set wrapmargin=n     Automatically wrap word in last n columns.
:set wrapscan         Searches reaching the bottom continue from the top.

   To unset any of these options, use the prefix no. For instance, the
   command :set nowrapscan will turn off the wrapscan feature. To make
   settings permanent, place them in the file .exrc in your home
   directory.
   
                                                                         
    Last modified Thursday, November 20, 1997 by Roger
    (rem@cco.caltech.edu).