Vim Cheat Sheet
By Marcus Braun
January 12, 2011
This is a list of Vim commands I use most frequently. Remember that most of these commands accept an optional quantifier which allows you to easily repeat actions (e.g. 10h moves 10 characters to the left).
Motion
Basic Movement
| Action |
Command |
| Character to the left |
h |
| Character to the right |
l |
| Character below |
j |
| Character above |
k |
Movement within a Line
| Action |
Command |
| Beginning of the line |
0 |
| Last character |
$ |
| Word to the left |
b |
| Word to the right |
w |
| End of word to the right |
e |
Search for x to the right |
fx |
Search up to x to the right |
tx |
Search for x to the left |
Fx |
Search up to x to the left |
Tx |
| Find the next match |
; |
| Find the previous match |
, |
Move to column x |
x| |
Movement amongst Lines
| Action |
Command |
| Go to first line in file |
gg |
| Go to last line in file |
G |
Go to line x |
xG |
| Go to matching brace, bracket, or parenthesis |
% |
| Go to first visible line |
H |
| Go to middle visible line |
M |
| Go to last visible line |
L |
Mark cursor position and associate with key a |
ma |
Jump to mark a |
`a |
| Return to the line jumped from |
`` |
Searching
| Action |
Command |
Search forwards for foo |
/foo |
Search backwards for bar |
?bar |
| Find the next match |
n |
| Find the previous match |
N |
| Toggle case insensitive searches |
:set ic, :set noic |
Scrolling
| Action |
Command |
| Scroll one line up |
Ctrl-e |
| Scroll one line down |
Ctrl-y |
| Half a screen down |
Ctrl-d |
| Half a screen up |
Ctrl-u |
| Full screen down |
Ctrl-f |
| Full screen up |
Ctrl-b |
| Re-center screen on cursor |
zz |
Editing
Insertion
| Action |
Command |
| Insert before the cursor |
i |
| Append after the cursor |
a |
| Append to the end of the line |
A |
| Open a new line below the current |
o |
| Open a new line above the current |
O |
| Exit insert mode |
Ctrl-[ or Esc |
Deletion
| Action |
Command |
| Delete character under the cursor |
x |
| Delete character before the cursor |
X |
| Delete current line |
dd |
| Delete from cursor to end of line |
D |
Delete from cursor through next occurrence of x |
dfx |
Delete from cursor up to next occurrence of x |
dtx |
Delete motion (use with marks, search, etc.) |
dmotion |
| Join current line with next (delete newline) |
J |
Modification
| Action |
Command |
Replace character with x |
rx |
| Replace multiple characters starting at the cursor |
R |
| Replace line (delete line, enter insert mode) |
cc |
| Replace from cursor to end of line |
C |
Replace from cursor through next occurrence of x |
cfx |
Replace from cursor up to next occurrence of x |
ctx |
Replace motion (use with marks, search, etc.) |
cmotion |
| Indent line right |
>> |
| Indent line left |
<< |
Indent motion right |
>motion |
Copy & Paste, Find & Replace, Repeat
| Action |
Command |
| Yank a line |
yy |
Yank motion (use with marks, search, etc.) |
ymotion |
| Put yanked/deleted/overwritten text after the cursor |
p |
| Put yanked/deleted/overwritten text before the cursor |
P |
Replace all occurences of foo with bar |
:%s/foo/bar/g |
Replace foo with bar on lines 1-5 |
:1,5s/foo/bar/g |
Replace foo with bar on current line |
:s/foo/bar/g |
| Repeat previous edit sequence |
. |
copyright © 2011 Marcus Braun