vi cheatsheet

Get the PDF here.

The bare minimum vi.

How to open a new or existing file in vi

vi filename

File navigation

Use [Page Up] , [Page Down]  to page through the file. Use the arrow keys to move the cursor.

Command mode and insert mode

When you first start vi, you are in command mode

To switch to insert mode

i

Once in insert mode, you can type in your text file.

To switch from insert mode to command mode

[ESC]

Command mode

Quit without saving changes

:q!

Quit

:q

Write (save)

:w

Write a copy of the file to another name

:w filename

Search for a string (replace “search” with the string you are searching for)

:/search

Global search and replace (replace “search” and “replace” with the strings you are searching and replacing)

:%s/search/replace/