A built-in text editor of the Unix system is called vi. The name vi is derived from the shortest unambiguous abbreviation for the command visual.

  1. From the Unix system prompt, you start up vi by typing:
    vi filename
  2. This will open a file called filename. If a file of that name doesn't already exist, it starts a new one.
  3. Vi has a command mode and an insert (or "editing") mode. You're, initially, always in command mode. Commands:
    1. Use the a and i commands (see below) to get to editing mode.
    2. The escape key takes you out of editing mode and puts you back in command mode.
  4. Unless otherwise noted, enter the following commands by simply typing them; you don't need to press the Return key. Commands should be typed in lowercase letters, unless otherwise indicated. The current line refers to the line on which your cursor is placed.

Common Commands

Command Description
a
For "append". Puts you in insert (or "editing") mode. Any characters that you type subsequently will be added to your file to the right of your cursor.
i For "insert". Puts you in editing mode (if you are in command mode); characters that you type subsequently will be inserted to the left of your cursor.
<Return> Hitting the Return key starts a new line (if you are in editing mode).
<Esc> Hitting the Esc key takes you out of insert (or "editing") mode and returns you to command mode.

Common Keyboard Shortcuts

Command Description
h (or ←) Moves your cursor one character to the left.
j (or ↓) Moves your cursor down one line.
k (or ↑) Moves your cursor up one line.
l (or →) Moves your cursor one character to the right.
^f Scroll forward one screenful.
^b Scroll backward one screenful.
x Deletes the character on which your cursor lies.
dd
Deletes the current line.
u Undoes your last command.
J Joins the next line with the current line.
ZZ Save your work and quit vi.
:w <Return> Writes (saves) your changes. (Typed sequentially.)
:wq <Return> Saves your changes and quits vi. (Typed sequentially.)
:q! <Return> Quits vi without saving your changes. (Typed sequentially.)