# 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
Replace mode (overwrite as you type)
R
Back to Normal mode
Esc / Ctrl + [
Run one Normal command from Insert mode
Ctrl + o
:motions 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
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
:editing vim editing 14 keys # Change text without leaving Normal mode.
Delete the character under the cursor
x
Delete to the end of the line
D
Paste after / before the cursor
p / P
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
:operators 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 up to a character
dt{char}
Uppercase / lowercase the word
gUiw / guiw
Re-indent the paragraph
=ap
Re-indent the whole file
gg=G
:search vim search and replace 10 keys # Find text and substitute it.
Search forward / backward
/pattern / ?pattern
Next / previous match
n / N
Search the word under the cursor forward / backward
* / #
Replace in the whole file
:%s/old/new/g
Replace in the whole file, asking each time
:%s/old/new/gc
Replace on the current line
:s/old/new/g
Replace in the visual selection
:'<,'>s/old/new/g
Clear the search highlight
:noh
Delete every line that matches
:g/pattern/d
Delete every line that does not match
:v/pattern/d
:visual 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
:'<,'>sort
:files vim files and buffers 13 keys # Save, quit and move between open files.
Save with sudo (Vim only)
:w !sudo tee %
Open a file
:e path/to/file
Reload the file, dropping changes
:e!
Save as a new file
:w newname.txt
Insert another file below the cursor
:r path/to/file
Next / previous buffer
:bn:bp
:windows vim windows and tabs 8 keys # Split the screen and use tab pages.
Split horizontally / vertically
Ctrl + w then s / Ctrl + w then v
:sp:vsp
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
:tabnew:tabe path/to/file
Next / previous tab
gt / gT
:registers 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
Jump to mark a / to its line
`a / 'a
Record a macro into a, then stop
qa / q
Play macro a / play the last macro
@a / @@
Play macro a ten times
10@a
:config vim settings and command line 8 keys # Run at the : prompt, or put in your vimrc without the colon.
Line numbers / relative line numbers
:set number:set relativenumber
Highlight search results as you type
:set hlsearch incsearch
Case-insensitive search unless you type capitals
:set ignorecase smartcase
Indent with 2 spaces
:set expandtab shiftwidth=2 tabstop=2
Turn on syntax highlighting
:syntax on
Insert the output of a shell command
:r !date
Open help on a topic
:help motion
:cli vim opening Vim 6 keys # Start Vim from the shell.
Open a file
$ vim file.txt
Open at line 42
$ vim +42 file.txt
Open files side by side
$ vim -O a.txt b.txt
Compare two files
$ vim -d a.txt b.txt
Open read-only
$ vim -R file.txt
Start without any config or plugins
$ vim --clean