Tip Run vimtutor in a terminal to learn the first
Vim commands.
Left-right motions
┌───────────── | ├───────────── 0 $ ──────────────┐ │ ┌────────── ^ fe ────────┐ │ │ │ ┌─────── Fo te ───────┐│ │ │ │ │┌────── To 30| ───┐ ││ │ │ │ ││ ┌──── ge w ───┐ │ ││ │ │ │ ││ │ ┌── b e ─┐ │ │ ││ │ │ │ ││ │ │ ┌h l┐ │ │ │ ││ │ ▽ ▽ ▽▽ ▽ ▽ ▽▼ ▼▽ ▽ ▽ ▽ ▽▽ ▽ echo "A cheatsheet from quickref.me"
Up-down motions
`- SCREEN 1 START ┌─┬─────────▷ #!/usr/bin/python │ │ ┌───▷ │ │ │ print("Hello") │ │ { } ▶ print("Vim") │ │ │ print("!") │ │ └─▷ │ │ ┌───┬───▷ print("Welcome") G gg H M L k j ▶ print("to") │ │ └─▷ print("quickref.me") │ │ print("/vim") │ │ │ └─────▷ │ - SCREEN 1 END └──────────────▷ print("SCREEN 2")`
Motions
h | j | k | l |
Arrow keys |
<C-u> / <C-d> |
Half-page up/down |
<C-b> / <C-f> |
Page up/down |
Words
b / w |
Previous/Next word |
ge / e |
Previous/Next end of word |
Line
0 (zero) / $ |
Start/End of line |
^ |
Start of line (non-blank) |
Character
Fe / fe |
Move to previous/next e |
To / to |
Move before/after previous/next o |
\| / n\| |
Go to first/nth column |
Document
gg / G |
First/Last line |
:n | nG |
Go to line n |
} / { |
Next/Previous empty line |
Window
H / M / L |
Top/Middle/Bottom screen |
zt / zz / zb |
Top/Center/Bottom this line |
Insert Mode
i / a |
Insert before/after cursor |
I / A |
Insert start/end of line |
o / O (letter) |
Insert new line below/above |
s / S |
Delete char/line and insert |
C / cc |
Change to end of/current line |
gi |
Insert at last insert point |
Esc | <C-[> |
Exit insert mode |
Saving and Exiting
:w |
Save |
:q |
Close file |
:wq | :x | ZZ |
Save and quit |
:wqa |
Save and quit all files |
:q! | ZQ |
Force quit |
:qa |
Close all files |
:qa! |
Force quit all files |
:w now.txt |
Write to now.txt |
:sav new.txt |
Save and edit new.txt |
:w !sudo tee % |
Write to readonly file |
r |
Replace one character |
R |
Enter Replace mode |
u / 3u |
Undo changes 1 / 3 times |
U |
Undo changes on one line |
J |
Join with next line |
<C-r> / 5 <C-r> |
Redo changes 1 / 5 times |
Cut and paste
x |
Delete character (Cut) |
p / P |
Paste after/before |
xp |
Swap two characters |
D |
Delete to end of line (Cut) |
dw |
Delete word (Cut) |
dd |
Delete line (Cut) |
ddp |
Swap two lines |
yy |
Yank line (Copy) |
"*p | "+p |
Paste from system clipboard |
"*y | "+y |
Paste to system clipboard |
In visual mode
d | x |
Delete selection (Cut) |
s |
Replace selection |
y |
Yank selection (Copy) |
Repeating
. |
Repeat last command |
; |
Repeat
latest f, t, F or T |
, |
Repeat
latest f, t, F or T reversed |
& |
Repeat last :s |
@: |
Repeat a command-line command |
Visual mode
v |
Enter visual mode |
V |
Enter visual line mode |
<C-v> |
Enter visual block mode |
ggVG |
Select all text |
> / < |
Shift text right/left |
Macros
qi |
Record macro i |
q |
Stop recording macro |
@i |
Run macro i |
7@i |
Run macro i 7 times |
@@ |
Repeat last macro |
You can save macro for any letters not just i
#Vim
Operators
Usage
Combine operators with motions to use them
Available Operators
d |
Delete |
y |
Yank (copy) |
c |
Change (delete then insert) |
p |
Paste |
= |
Formats code |
g~ |
Toggle case |
gU |
Uppercase |
gu |
Lowercase |
> |
Indent right |
< |
Indent left |
! |
Filter through external program |
Examples
| Combination |
Description |
dd |
Delete current line |
dj |
Delete two lines |
dw |
Delete to next word |
db |
Delete to beginning of word |
dfa |
Delete until a char |
d/hello |
Delete until hello |
cc |
Change current line, synonym with S |
yy |
Copy current line |
>j |
Indent 2 lines |
ggdG |
Delete a complete document |
gg=G |
Indent a complete document |
ggyG |
Copy a whole document |
Counts
[count] <operator> <motion> <operator> [count] <motion>
2dd |
Delete 2 lines |
6yy |
Copy 6 lines |
d3w |
Delete 3 words |
d5j |
Delete 5 lines downwards |
>4k |
Indent 4 lines upwards |
#Vim Text
objects
Usage
v |
i / a |
p |
| Operator |
inner / around |
Text object |
Operate with an operator inner
or around text blocks
Text objects
| p |
Paragraph |
| w |
Word |
| W |
WORD (surrounded by whitespace) |
| s |
Sentence |
| [ ( { < |
A [], (), or {} block |
| ] ) } > |
A [], (), or {} block |
| ’ “ ` |
A quoted string |
| b |
A block [( |
| B |
A block in [{ |
| t |
A HTML tag block |
See :help text-objects
Delete
diw |
Delete inner word |
dis |
Delete inner sentence |
di” |
Delete in quotes |
da” |
Delete in quotes (including quotes) |
dip |
Delete a paragraph |
Selections
vi” |
Select inner quotes “...” |
va” |
Select quotes "..." |
vi[ |
Select inner brackets [...] |
va[ |
Select brackets [...] |
viw |
Select inner word |
vip |
Select inner paragraph |
vipip |
Select more paragraph |
Misc
ciw |
Change inner word |
ci” |
Change inner quotes |
cit |
Change inner tags (HTML) |
cip |
Change inner paragraph |
yip |
Yank inner paragraph |
yap |
Yank paragraph (including newline) |