VI Cheat Sheet

File Management Commands

Window Motions

Cursor Motions

Command Mode vs Input Mode

Vi starts in command mode. The positioning commands operate only while vi is in command mode. You switch vi to input mode by entering any one of several vi input commands. Once in input mode, any character you type is taken to be text and is added to the file. You cannot execute any commands until you exit input mode.

To exit input mode, press the escape (Esc) key.

Input Commands (end with Esc)

Change Commands (Input Mode)

Changes During Insert Mode

Deletion Commands

Recovering Deletions

Undo Commands

Rearrangement Commands

Parameters

Moving Text Between Files

To move text from file old to file new:

vi old
"a10yy         # yank 10 lines to buffer a
:w             # write work buffer
:e new         # edit new file
"ap            # put text from a after cursor
:30,60w new    # Write lines 30 to 60 in file new

Regular Expressions (Search Strings)

Search and Replace Commands

Syntax: :[address]s/old_text/new_text/

Address Components:

Examples: