CSU Long Beach
CECS 274
Programming and Problem Solving II


Syllabus
Schedule
Grading
Project 1
Project 2
Solution to Project 2
Project 3
Solution to Project 3
Project 4
Solution to Project 4
Project 5
Set Solution to Project 5
Map Solution to Project 5
Lecture Notes
Basic Unix Commands
Basic vi Commands
More vi Commands
Using Eclipse
Compiling and Running Java on Unix


Mimi Opkins Home

Basic vi Commands

     

    vi(sual) is a display oriented text editor available on most Unix systems. We will be using vi to create and edit files in Unix.

    vi operates in two modes: insert and command. When you are in insert mode, the characters you type will be added to the file you are editing. When you are in command mode, the characters you type will be interpreted as commands to move around or edit the file. It is important to remember which mode you are currently "in" when you are using vi.

    To invoke the vi editor, from the Unix command line, type  "vi file_name"  where file_name is the name of the file you wish to edit or create.  If the file exists you will be allowed to edit it; if it does not exist, a new file of the specified name will be created for you.

    Here is a set of the basic commands you will need to use the editor:

     

    Name

    Command

    Description

    arrow keys

    ¬  ¯    ­    ®

             or

    H    J K    L

    These keys move you around the file. 

    Warning: you are not allowed to move around the file using the arrow keys while in insert mode; you will get "funny" results.

    insert

    i

    Begins the insertion in front of the current cursor position.

    append

    a

    Begins the insertion after the current cursor position.

    escape

    <esc>

    Ends the insertion and puts you in command mode.

    delete

    d number item

    Deletes some number of items, where number is an integer and items can be l (for letter), w (for word), or d (for line).  For example, "d12w" deletes the next 12 words.

    undo

    u

    In case of a mistake while in command mode, use "u" to undo the last command.

    search

    / pattern

    When in command mode, this allows you to search your file for the pattern you specify.

    write and quit

    :wq

    Saves the changes you have made to your file and exits the editor.  If you really goof up, and don't want to save the changes you have made, use the "q!" command.

    delete a character

    x

    Deletes the character directly underneath the cursor.

    The editor has many other commands--one for just about every key--and capitol letters represent different commands from their lowercase counterparts. If you get into trouble remember the "u".