vi Tutorial


vi has two modes - command mode and insert mode. In command mode, you are not directly typing text into the file. Instead, you are giving commands like delete a single line, delete several lines, paste several lines, replace all instances of “hello” with “howdy”, save the file, quit, move the cursor, and so on. At any time, to get into command mode, you hit the esc key. In insert mode, you can type normally.

There are a few ways to get into command mode:

Below is a set of very useful vi commands which apply in command mode:

Moving the Cursor Around

Moving Text Around

Inserting Text

Note that these all move into insert mode.

Saving Files and Quitting

Note the use of the colon (:) before these commands.

Useful Complicated Commands

Note the use of the colon (:) before these commands.


Prepared for Computer Science 64 by Prof. Diana Franklin, with slight adaptation by Kyle Dewey.