| Command | Description |
|---|---|
h | Move left |
j | Move down |
k | Move up |
l | Move right |
- | Move to the beginning of the previous line |
+ | Move to the next line |
0 | Move to the beginning of the line |
$ | Move to the end of the line |
^ | Move to the first non-space/tab character in the current line |
b | Move to the beginning of the previous word |
B | Move backward by words (ignoring punctuation) |
e | Move to the end of the current/next word |
E | Same as e, ignoring punctuation |
1G | Move to the first line |
nG | Move to line n |
G | Move to the last line |
w | Move to the beginning of the next word |
W | Same as w, ignoring punctuation |
) | Move to the beginning of the next sentence |
( | Move to the beginning of the previous sentence |
} | Move to the beginning of the next paragraph |
{ | Move to the beginning of the previous paragraph |
| Command | Description |
|---|---|
/pattern |
Search forward for pattern. |
?pattern |
Search backward for pattern. |
/ |
Repeat the last forward search. |
? |
Repeat the last backward search. |
n |
Repeat the previous search in the same direction. |
N |
Repeat the previous search in the opposite direction. |
| Command | Description |
|---|---|
r |
Replace a single character. |
R |
Enter Replace mode and overwrite existing text. |
~ |
Toggle the case of the current character. |
:s/pattern/replace/ |
Replace the first occurrence of pattern with replace in the current line. |
:lines/s/pattern/replace/ |
Replace the first occurrence of pattern on the specified line(s). |
:line1,line2/s/pattern/replace/ |
Replace the first occurrence of pattern in each line of the specified range. |
:%s/pattern/replace/ |
Replace the first occurrence of pattern in every line of the file. |
:1,$s/.$// |
Remove the last character from every line (commonly used to remove ^M characters). |
| Command | Description |
|---|---|
i |
Insert text before the cursor. |
I |
Insert text at the beginning of the current line. |
a |
Insert text after the cursor. |
A |
Insert text at the end of the current line. |
o |
Open a new line below the current line and enter Insert mode. |
O |
Open a new line above the current line and enter Insert mode. |
| Command | Description |
|---|---|
x |
Delete the character under the cursor. |
X |
Delete the character to the left of the cursor. |
s |
Substitute the character under the cursor and enter Insert mode. |
S |
Substitute the entire current line and enter Insert mode. |
D |
Delete from the cursor to the end of the line. |
dw |
Delete from the cursor to the end of the current word. |
dd |
Delete the current line. |
ndd |
Delete n consecutive lines. |
dG |
Delete from the current line to the end of the file. |
d1G |
Delete from the current line to the beginning of the file. |
J |
Join the next line with the current line. |
cc |
Replace the entire current line and enter Insert mode. |
cw |
Replace from the cursor to the end of the current word. |
C |
Replace from the cursor to the end of the line. |
c$ |
Replace from the cursor to the end of the line. |
xp |
Transpose two adjacent characters. |
u |
Undo the last change. |
. |
Repeat the last change. |
| Command | Description |
|---|---|
yy |
Yank (copy) the current line. |
nyy |
Yank (copy) n consecutive lines. |
yw |
Yank from the cursor to the end of the current word. |
y$ |
Yank from the cursor to the end of the current line. |
p |
Paste the yanked or deleted text after the cursor (or below the current line for linewise text). |
P |
Paste the yanked or deleted text before the cursor (or above the current line for linewise text). |
| Command | Description |
|---|---|
:w |
Write (save) the file without exiting Vim. |
:wq |
Write (save) the file and quit Vim. |
:q |
Quit Vim. Fails if there are unsaved changes. |
:q! |
Quit Vim and discard all unsaved changes. |
| Command | Description |
|---|---|
:line r file |
Insert the contents of file after the specified line. |
:r file |
Insert the contents of file after the current line. |
:line r !cmd |
Insert the output of cmd after the specified line. |
:r !cmd |
Insert the output of cmd after the current line. |