S5 version Table of Contents (frame/ no frame)
(22) The vi editor Previous Top Next

The vi editor

Vi has modes. Insert mode and command mode. When you first enter vi you are in command mode and anything you type will be interpreted as a command. This of this as selecting actions from the menus in MS Word.
Vi needs to be able to address the terminal window you are working in, so the setting of the $TERM variable is important. Some systems get confused by resizing the terminal window while vi is running.

When you are in command mode many commands which affect more than one line of the file are prefaced with a ":". An example is :w which writes out or saves the current file.

When you are in insert mode you can type in text, when you are in command mode you can issue commands to vi (search for a string, save the file ...).

Basic vi commands:

vi file_name or vi
Enters vi using the named file as the file to edit.
view file_name
Opens a file in read only mode. Means that you cannot easily change the file. If you make a change to the file you can force it to write with :w!.
<esc>
The escape key, tells vi to leave insert mode and go into command mode. You cannot exit vi unless you are in command mode.
ZZ
Exit vi.
:set showmode
Shows insert mode in the lower right hand corner of the screen. Very helpful when first learning vi.
:q!
Force a quite without saving (if you mess up)

Previous Top Next


slide23.src  last modified Jan 31, 2011 Introduction Table of Contents
(frame/no frame)
Printable
(single file)
© Dartmouth College