vi editor Quick Reference & Cheat Sheet

Updated Jun 2026 · originally published Dec 2009 · Tested on Linux, Unix

Introduction

Learn about the default text editor, vi, pronounced as ”vee eye”, in Unix, Linux and other Unix like systems. A short, concise vi quick reference lets you get started with vi today. Explains vi editor mode & vi commands with examples for editing in vi. Click to download and print

vi editor Cheat Sheet

in PDF format.

In order to work correctly the vi need correct terminal type (TERM) setting depending on the type of terminal you have. Commonly used TERM types are vt100 , vt220 and ansi. In most cases vt100 will work fine. In case vi is not able to understand the TERM you have given, it starts in open mode giving you a line by line display . TERM’s value is taken from .profile or /etc/profile but can be set at the command line as : $TERM=vt100 $export TERM echo $TERM will display the current TERM set.

Modes in vi

vi operates in following two modes : i.)

Command Mod

e: After a file is opened it is opened in command mode and input from the keyboard will be treated as vi commands, you will not see the words you are typing on the screen ii.)

Insert Mode

: vi enters in insert mode by pressing letter ‘i’ or ‘a’ and it will accept letter typed as input iii)

Switch between vi mode

: Press Esc key to swich modes, Esc -> i (text mode) -> Esc (command mode)

Following sections provide a vi quick referance to perform everyday tasks.

  1. File Open/Save/Quit
  2. Moving Around
  3. Editing
  4. Operations
  5. Search/Replace

File Open/Save/Quit

CommandDescription
vi filenameOpen or create file
viOpen new file to be named later
vi -r filenameRecover crashed file
view filenameOpen file read-only
Saving and Quitting
:w
:w filename
:wq
ZZ
:q!

Moving Around

Moving Cursor in file
h
j
k
l
w
W
b
B
e
Moving Cursor with keys
Return/Enter key
Backspace
Spacebar
Moving on Screen
H
M
L
Moving on Screen using ctrl key combination
Ctrl-f
Ctrl-d
Ctrl-b
Ctrl-u

Editing

Insert Characters and Lines
a
A
i
I
o
O
Text Change Operations
cc
cw
C
s
r
r Return
J
xp
~
u
U
:u
Delete Text in file
x
X
dw
dd
D
dG
d1G
:1,4 d
Copy and Move lines
yy
4yy
Y
p
P
:1,2 co 3
:4,6 m 7
Inserting a File Into a File
:r filename
:34 r filename

Operations

Show/hide Line Numbers
:set nu
:set nonu
set/ignore case for search
:set ic
:set noic
go to line
G
1G
21G
Clearing the Screen
Ctrl-L

Search and Replace

Search and Replace
/string
?string
n
N
:%s/search/s/replace/g