Skip to content

vi Command Cheat Sheet

vi is a screen-oriented text editor originally created for the Unix operating system. Note: On most modern Linux systems, vi is a symlink to vim (Vi IMproved) or elvis.


Modes

  1. Command Mode (Default): For navigation and manipulation. Press Esc to return here.
  2. Insert Mode: For typing text. Press i, a, o to enter.
  3. Last Line Mode: For saving/exiting. Press : from Command Mode.

Basic Workflow

  1. Open file: vi file.txt
  2. Enter Insert Mode: Press i
  3. Type text...
  4. Exit Insert Mode: Press Esc
  5. Save and Exit: Type :wq and Enter

Key Action
h Left
j Down
k Up
l Right
w Jump forward to start of word
b Jump backward to start of word
0 Start of line
$ End of line
gg Go to first line
G Go to last line
10G Go to line 10

Editing

Key Action
i Insert at cursor
a Append after cursor
A Append at end of line
o Open new line below
O Open new line above
x Delete character at cursor
dd Delete current line
yy Yank (copy) line
p Paste after cursor
u Undo
Ctrl+r Redo

Command Action
/text Search forward for "text"
?text Search backward for "text"
n Next match
N Previous match

Saving and Quitting

Command Action
:w Save (Write)
:q Quit
:wq Save and Quit
:x Save and Quit (Same as :wq)
:q! Quit without saving (Force)