~/cheatsheets (main) $ vim --help

vim cheat sheet

Vim is modal: Normal mode moves and edits, Insert mode types text, Visual mode selects, and : opens the command line. The keys below work in Normal mode unless they say otherwise; press Esc to get back to it. Commands that start with a colon are typed at the bottom and run with Enter. Neovim uses the same keys: switch to nvim and the shell commands update. Click a command to copy it.

editor
print

vim modes

10 keys

# Get into a mode, and back to Normal with Esc.

Insert before the cursor / after it
i / a
Insert at the start / end of the line
I / A
Open a new line below / above
o / O
Visual mode by character
v
Visual mode by line
V
Visual block mode
Ctrl+v
Replace mode (overwrite as you type)
R
Back to Normal mode
Esc / Ctrl+[
Open the command line
:
Run one Normal command from Insert mode
Ctrl+o

vim motions

15 keys

# Move around. Put a number first to repeat (5j moves down 5 lines).

Left, down, up, right
h / j / k / l
Next word / back a word / end of word
w / b / e
Same, by space-separated WORD
W / B / E
Start of line / first character / end of line
0 / ^ / $
First line / last line of the file
gg / G
Go to line 42
42G
Half a page down / up
Ctrl+d / Ctrl+u
A page down / up
Ctrl+f / Ctrl+b
Top / middle / bottom of the screen
H / M / L
Jump to the matching bracket
%
Jump to / just before a character on the line
f{char} / t{char}
Repeat that jump forward / backward
; / ,
Previous / next paragraph
{ / }
Scroll so the cursor is centred / at the top / at the bottom
zz / zt / zb
Back / forward through the jump list
Ctrl+o / Ctrl+i

vim editing

14 keys

# Change text without leaving Normal mode.

Delete the character under the cursor
x
Delete the line
dd
Delete to the end of the line
D
Copy (yank) the line
yy
Paste after / before the cursor
p / P
Undo / redo
u / Ctrl+r
Repeat the last change
.
Join the next line onto this one
J
Replace one character
r{char}
Toggle case of the character
~
Indent / unindent the line
>> / <<
Change the whole line / to the end of the line
cc / C
Swap two characters / two lines
xp / ddp
Increment / decrement the number under the cursor
Ctrl+a / Ctrl+x

vim operators and text objects

11 keys

# Operator + motion or text object: d (delete), c (change), y (yank).

Delete to the end of the word
dw
Change the word under the cursor
ciw
Delete the word and the space after it
daw
Change inside quotes / parentheses / braces
ci" / ci( / ci{
Change inside an HTML tag
cit
Delete the paragraph
dap
Yank inside braces
yi{
Delete up to a character
dt{char}
Uppercase / lowercase the word
gUiw / guiw
Re-indent the paragraph
=ap
Re-indent the whole file
gg=G

vim visual mode

6 keys

# Select first, then act on the selection.

Jump to the other end of the selection
o
Select the last selection again
gv
Indent / unindent the selection
> / <
Yank / delete / change the selection
y / d / c
Insert / append on every line of a block
Ctrl+v then I / Ctrl+v then A
Sort the selected lines

vim files and buffers

13 keys

# Save, quit and move between open files.

Save
Save and quit
ZZ
Quit
Quit without saving
ZQ
Save with sudo (Vim only)
Open a file
Reload the file, dropping changes
Save as a new file
Insert another file below the cursor
List buffers
Next / previous buffer
Go to buffer 2
Close the buffer

vim windows and tabs

8 keys

# Split the screen and use tab pages.

Split horizontally / vertically
Ctrl+w then s / Ctrl+w then v
Move to the window in a direction
Ctrl+w then h / Ctrl+w then j / Ctrl+w then k / Ctrl+w then l
Go to the next window
Ctrl+w then w
Close the window / every other window
Ctrl+w then q / Ctrl+w then o
Make all windows the same size
Ctrl+w then =
Open a new tab
Next / previous tab
gt / gT
Close the tab

vim registers, marks and macros

9 keys

# Named clipboards, bookmarks and recorded keystrokes.

Yank the line into register a / paste from it
"ayy / "ap
Yank to / paste from the system clipboard
"+y / "+p
Show all registers
Set mark a
ma
Jump to mark a / to its line
`a / 'a
List marks
Record a macro into a, then stop
qa / q
Play macro a / play the last macro
@a / @@
Play macro a ten times
10@a

vim settings and command line

8 keys

# Run at the : prompt, or put in your vimrc without the colon.

Line numbers / relative line numbers
Highlight search results as you type
Case-insensitive search unless you type capitals
Indent with 2 spaces
Turn on syntax highlighting
Run a shell command
Insert the output of a shell command
Open help on a topic

vim opening Vim

6 keys

# Start Vim from the shell.

Open a file
Open at line 42
Open files side by side
Compare two files
Open read-only
Start without any config or plugins