This cheat sheet is intended to be a quick reminder for the main concepts involved in using the command line program Vim (or vi) and assumes you already understand its usage. It does not cover every command in Vim, only the ones we consider to be useful for most people for the majority of their text editing.

Visit the Vi page in our tutorial for a more in depth discussion on their usage.

Main Linux Cheat Sheet page.

Basic Usage

vim or vi
Run vim and open the given filename.
:w
Save file.
:x or SHIFT ZZ
Save and exit.
:q
Exit if no changes have been made.
:q!
Exit and undo any changes made.
:set nu
Display line numbers.

Movement

h
Move left one character.
j
Move down one character.
k
Move up one character.
l
Move right one character.
w
Move forward one word.
b
Move to the start of the word.
e
Move to the end of the word.
(
Move back one sentence.
)
Move forward one sentence.
{
Move back one paragraph.
}
Move forward one paragraph.
^
Move to the beginning of the line.
$
Move to the end of the line.
<n>G
Move to the nth line.
G
Move to the last line.
gg
Move to the first line.
%
Move to the matching bracket.

Deleting

x
Delete a single character.
D
Delete the rest of the line.
dd
Delete the entire current line.
ndw
Delete the next n words.
ndd
Delete the next n lines.
:x,yd
Delete from line x through to line y.

Entering Insert mode

i
At the cursor.
a
After the cursor.
I
Before the current line.
A
After the current line.
o
Insert a new line after the current line.
O
Insert a new line before the current line.
C
Ovewrite the whold current line.
ESC
Exit Insert mode.

Cut and Paste

p
Paste the clipboard contents.
yy
Yank (copy) a line.
yw
Yank a word.
y$
Yank to the end of the line.