Bryn Mawr Computing Do IT  
 
Computing Services Home
 
* Do IT
* Use IT
* Learn IT
 
* News
* Policies
* Staff List
* About Us
* Contact the Help Desk
 
 
 Learn IT : Software Documentation : Unix-vi  
 

vi is a text editing program which allows you to create and edit files in UNIX. vi is the default text editor in Elm, a UNIX mail program. There are various operating modes (Command, Text Input, and Last Line) which allow you to create or edit files, add or delete specific lines or characters within files, or even search for specified patterns within files.

Creating or Opening a File Saving and Searching
Entering Text Quitting vi
Maneuvering and Editing in Command Mode  
Creating or Opening a File

Entering the text editor is fairly simple: at the UNIX prompt, type vi filename, where filename is the name of the file you wish to edit or create. If the specified filename already exists, the vi editor will open the document. If the specified filename does not exist, the vi editor will create a file with that name. The vi editor will start in Command mode.

Entering Text

In order to enter text, you will first need to enter the Text Input mode. Pressing the Escape key will return you to Command mode.
 

Command

What it does

i, a Inserts text at the cursor position (I) or after the cursor position (a).
I, A Inserts text at the beginning (I) or end (A) of a line.
o, O Inserts a new line for text below (o) or above (O) the cursor position.
R Allows you to type over characters instead of inserting additional characters.

Maneuvering and Editing in Command Mode

vi launches in Command mode. Command mode allows you to move through, and edit, a document. When in another mode, press the Escape key to return to Command mode. To cancel an uncompleted command code, press Escape. Quitting vi is another Command mode code, which is covered at the end of this document.
 

Command

What it does

h, l Moves left (h) or right (l) by one character.
j, k Moves down (j) or up (k) by one line.
w, W, b, B Moves forward (w) or backwards (b) by a word or words; 3w would move forward 3 words.
+, - Moves to the first character of the next (+) or previous (-) line.
x, X Deletes the character at or before the cursor, respectively.
dd Deletes the current line.
u Undo the last command.
r Replaces the current character with the next typed character.

Saving and Searching

From Command mode you can access the Last Line mode, which allows you to perform searches and save, amongst other things. Certain character sequences (:,/, ?, and !!) enable the switch from Command mode, acting as prefixes for Last Line commands.
 

Command

What it does

:w Saves (writes) the file without quitting.
/pattern Searches for a specified pattern in a document.
? Searches backwards for a specified pattern
/,? Repeats the last forward or backwards search, respectively.
! Overrides any protection (e.g., q! as seen below).

Quitting vi

There are a few ways to quit vi, depending on what you intend to do. Remember to press the Escape key first, if you are not in Command mode.
 

Command

What it does

:q This exits the editor without saving the file, if no changes have been made.
:q! This exits the editor without saving the file, disgarding all changes.
:wq This exits the editor and saves the updated, altered file.


^ Top

 

 
  Information Services
Contact Us   |   Bryn Mawr Library   |   Search CS