Vi For Smarties

Lesson One

Basic Concepts

  1. Start by typing vi followed by the file(s) you want to edit.
    Example: vi one.txt two.txt etc.txt
  2. There are two modes: command mode and insert mode. You will begin in command mode. (Unless you have a config file which changes this. Rare.)
  3. Hitting the Esc key always puts you in command mode.
    It never takes you out of command mode.
  4. Commands only work in command mode. Get used to hitting Esc a lot.
  5. Esc is your friend. If you begin to issue a command and then change your mind, always hit Esc a few times to cancel.

Basic Editing Commands

  1. Hitting i or a from command mode puts you in insert mode. i starts inserting text before the cursor. a starts appending text after the cursor.
  2. Use h j k l to move left, down, up, and right, respectively.
  3. Use w e b to move forward one word, forward to the next end of a word, and back one word, respectively.
  4. Use x to delete one character, dw to delete one word, or dd to delete one whole line.
  5. Use a number before a command to repeat the command that many times.
    Example: 3dw deletes three words starting from the current cursor position.
  6. u (lowercase) means undo the last change.
  7. ZZ (uppercase) saves any changes and quits.
  8. :q! abandons any changes and quits.

Until you have mastered everything on this page, you are not ready for Lesson Two.

Copyright © 2001 All rights reserved.