Introduction to the VI Editor

Vi is a text editor. To invoke vi just type vi at the prompt. Normally vi is invoked with a filename as an argument.

Syntax: vi [filename ...]

You can specify multiple filenames.

Vi has two (2) modes of operation. COMMAND MODE and TEXT ENTRY MODE. When you fist get into vi, you will be place in COMMAND MODE. Everything you type while in command mode will be interpreted as a command and will generally not appear on the screen. To enter text you have to be in TEXT ENTRY MODE.

Here is a list of several ways to get into TEXT ENTRY MODE

     i    insert text where your cursor is.
     I    insert text at the beginning of the line.
     a    start inserting text after the current character (append).
     A    append characters at the end of the line.
     o    open a line below the current line and go into insert mode.
     O    open a line above the current line and go into insert mode.
After each of these commands, you can start typing whatever you wish to type.
     Pressing the Esc key will bring you back to command mode.
You must be in command mode before you can move the cursor around or before entering any other command.

Commands available in command mode:

Cursor Movements:

     h         move cursor left
     j         move cursor down
     k         move cursor up
     l         move cursor right
     w         move to begining of next word
     e         move to end of word
     b         move to begining of word
     L         move to bottom of screen
     H         move to top of screen
     0         move to begining of line
     $         move to end of line
     Ctrl-d    move the screen down half a page
     Ctrl-u    move the screen up half a page
     Ctrl-b    move the screen back a full page
     Ctrl-f    move the screen forward a full page.
     nG        Moves the cursor to the nth line of the file.
               n is an integer.
     %         Move to matching () [] {}.
Text deletion commands

     x    deletes current character
     dd   deletes current line
     dw   delete from cursor to the beginning of next word
     db   delete from cursor to the beginning of previous word
     d)   delete the rest of the sentence.
     d}   delete the rest of the paragraph
These commands can be preceded by an integer to indicate the number of characters, words, etc., to be deleted.

Saving, reading, and quitting the editor. Must be in command mode so press <esc> before each command.

     :w   write the file to disk (save) (uses the filename specified)
     :r   read a file into the current editing session (uses a filename)
     :e   start editing the specified file.
     :wq  write the file to disk and quit.
     :q   quit.  If the file has been modified this will not work.
     :q!  really quit, without saving the file.
     ZZ   write and quit.
Search Commands.

     /pattern  Search for next occurence of pattern
     ?pattern  Search for previous occurence of pattern
     n         repeat last search command given.
The Last Command.

     u    Undo last command.
     U    Undo all changes on the current line
     .    Repeat last command.
Text moving.

     yy   yank a copy of a line and place it in a buffer.
     p    put after the cursor the last item yanked or deleted.
     P    put before the cursor the last item yanked or deleted.
Set Variables.

These are features that are set by using:
     :set var    or    :set novar
Where var is one of the following:
     ai   auto-indent
     num  line numbers
CAUTION:

Vi's command mode is case sensitive. Be careful when using the caps lock as it can produce unexpected results if you accidentally turn it on.


This list does not cover everything you can do with vi. There are many other commands. You can find out more about vi by entering the command "man vi" at the shell prompt.