FLOPPIX Home | FAQ | Download | Labs | ToC | Back |  Next 

A very brief introduction to vi


  1. vi is a powerful text editor; It is one of the standard Unix editors. However, it is also very complex; entire books have been written on vi usage and features.
  2. If you do much work on Unix systems, at some time you may have no other option; you will have to use vi.
  3. This lab covers a bare minimum of vi commands; enough to perform some very basic tasks.
  4. vi was designed to work on a multitude of terminals, many of which had no control keys and no cursor movement keys. So it is possible to use vi using h (left) j (down) k (up) and l (right) keys for cursor movement.
  5. vi is a moded editor;

Using vi:

  1. To start vi, type vi <filename>
  2. To get into insert mode and start entering text into the document press:
  3. To get back to command mode:
  4. To delete:
  5. To undo a command:
  6. To move a line or block of lines:
  7. To copy a line
  8. To exit:


  1. Use vi to create a file with the answers to these questions:
  2. Copy the file /etc/passwd to your own home directory.
    This file is the user database file. It contains one line for each user; each line contains seven fields separated by colons. The fields are:
    Edit the copy of the password file as follows:
    a. Find the line for your account. In this line:
        i. Change the username to joe.
        ii. Change the userid to 500.
    b. Find the line for the alterego account.
        i. Change the name to Dr. Freud.
        ii. Change the groupid to 600.
        iii. Change the shell to /usr/bin/flin.
    c. Find the line for the floopy account.
        i. Change the password to *.
    d. Add a new line: me:*:1004:100:me:/home/me:/bin/bash
    e. Delete the line for the games account.
    f. Save your work.

Questions & Answers:

For each question, assume that you are editing this file, you are in command mode and the cursor is on line 2, word 2 under the i.

There is a site on the Internet titled:
     Unix is a four letter word and vi is a two letter abbreviation.
The URL for this site is: http://www.linuxbox.com/~taylor/4ltrwrd/
  1. What happens if you type: dd
    Answer: the second line will be deleted.
  2. What happens if you type xiwa
    Answer: x deletes the letter over the cursor; i switches to insert mode; the letters wa are inserted.
    The start of the line becomes: Unix was a four letter word
  3. What happens if you type oC.C.Taylor
    Answer: A new line opens up under line 2. The new line will contain the text: C.C.Taylor
  4. What command do you use to save the file and quit?
    Answer: :wq
  5. What does it mean if you get the error message "File is temporary, exit will discard modifications" when you try to save and quit?
    Answer: You did not give a filename when you started vi. You will have to save the file with the command: [ESC]:w  <filename>

Copyright © L. M. MacEwan
FLOPPIX Home | FAQ | Download | Labs | ToC | Back |  Next