Webguide Home | Search
New York University

Web Site Development

Editing with vi

From the UNIX system prompt, you start up vi by typing

vi filename <Return>

Uses the editor vi to open a file called filename. If a file of that name does not already exist, it starts a new one. Vi has a command mode and an insert (or "editing") mode. You are always in command mode initially. The a and i commands (see below) will put you in editing mode. The escape key takes you out of editing mode and puts you back in command mode.

Unless otherwise noted, enter the following commands by simply typing them. (That is, you do not need to press <Return>.) Commands should be typed in lower case letters, unless otherwise indicated. The current line refers to the line on which your cursor is placed. You start out in command mode.

Command Description
To go into editing mode
a (once) 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 (once) 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> Return key. Starts a new line (if you are in editing mode).
<Esc> Esc key. Takes you out of insert (or "editing") mode and returns you to command mode.
Use these when in command mode
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.)