Help Desk
Division of Information Technology Home
 

Using vi


vi, a visual display editor, is a full screen-oriented text editor on the Unix operating system.  vi allows the user to create, examine, or edit files (programs, data, or documents).  In the vi command mode, you issue commands to move the cursor to a certain part of the file, to delete unwanted text, or to perform other editing functions.  In the text entry mode, your input is inserted as text directly into the file.  Type the Escape (ESC) key to return from the insert mode to the command mode.

Entering vi

You must specify the type of terminal you are using before entering the vi editor.  In Unix, type:

setenv TERM termtype

 

termtype specifies the type of terminal.  The terminal types are:
     vt100 for the DEC VT100 or TAB terminals,
     vt52 for the Teleray 10 terminal,  and
     adm3a for the Liberty Freedom 100 terminal.

Once you specify the terminal type, access the vi editory by typing:

vi filename

filename is the name of the file to be created or edited.

Leaving vi

:q!

Exits a vi session without saving the editing changes.

:wq

Saves and exits a vi session.

ZZ

Saves and exits a vi session.

:w

Writes the contents to the file.

Cursor Movement Commands

l

Moves the cursor one character to the right.

h

Moves the cursor one character to the left.

w

Moves the cursor forward one word.

b

Moves the cursor backward one word.

j

Moves the cursor down to the next line.

k

Moves the cursor uup one line.

)

Moves the cursor forward to the beginning of the next sentence.

(

Moves the cursor backward to the beginning of the currnet sentense.

}

Moves the cursor forward to the beginning of the next paragraph

{

Moves the cursor backward to the beginning of the current paragraph.

H

Moves the cursor to the top line of the screen.

M

Moves the cursor to the middle line of the screen.

L

Moves the cursor to the bottom line of the screen.

nG

Moves the cursor to the line number n; n is a numerical value.

Page Movement Commands

CTRL-D

Scrolls forward half a screenful.

CTRL-U

Scrolls backward half a screenful.

CTRL-F

Scrolls forward a screenful.

CTRL-B

Scrolls backward a screenful.

Inserting and Appending Text

i

Inserts a few characters or words into existing text or inserts text into a new file.

a

Puts vi in the text entry or insert mode and places the text the user types before the current character.

A

Places the text the user types after the last character on the current line.

Opening a Line of Text

O

Opens a blank line above the current line for inserting text.

o

Opens a blank line below the current line for inserting text.

Deleting a Character, Word, Line, Sentence, or Paragraph

x

Deletes the current

dd

Deletes the current

dw

Deletes the current

db

Deletes to the beginning of the current word, starting at the current position.

d)

Deletes text from the current position to the end of the sentence.

d(

Deletes text from the current position to the beginning of the sentence.

d}

Deletes text from the current position to the end of the paragraph.

d{

Deletes text from the current position to the beginning of the paragraph.

Changing a Character, Word, Line, Sentence, and Paragraph

r

Changes or replaces one character with another character.

R

Causes all subsequent characters you type to overwrite the existing text until you press the  ESC key to return vi to the command mode.

cw

Changes the current word, starting at the current position (the system has an end mark "$" to indicate the end of the change).

cb

Changes from the current position to the beginning of the current word (the system has an end mark "$" to indicate the end of the change).

cc

Changes the current line.

c)

Changes from the current position to the end of the sentence.

c(

Changes from the current position the beginning of the sentence.

c}

Changes from the current position to the end of the paragraph.

c{

Changes from the current position to the beginning of the paragraph.

Searching and Substituting Text

/

Searches forward for the user-specified text.

?

Searches backward for the user-specified text.

:[address]s/search-text/replace-text[/g];

address                is the specific line number(s) in the file.
search-text         is the string of text to be replaced.
replace-text        is the string of text to replcace fhe search-text.
/g                          indicates a global substitution.


Reading and Writing Text

r  filename

Reads or retrieves a file called filename into the editing session (if there is a file in the current editing sessaion, then this command will make the new file append to the old file).

:r filename

filename specifies the name of the file.

w

Writes parts of the text or all of the text modified in an editing session to a file.

:[address]w [filename]

address Specifies a certain portion of the modified text which is defined by a line number of line numbers;  the address parameter is optional.  If you omit the address parameter, vi will use the entire file.
filename Is the name of the file; the filename specification is optional. If the user omits the filename, vi writes the contents to the file you are editing.

Joining Text

J

Joins the line below the current line to the end of the current line.

TOP OF PAGE


HOME
Site Home | What We Do | Help Desk | Account Services | Software | Hardware | Network
Telephone Services | Training | Computer Labs | Web Publishing | Policies | Sitemap | Contact Us

San Francisco State University

Last Modified: 4 Feb 2004
doit@sfsu.edu