vim -> open vim
vim file.txt -> open file.txt in vim and create this file if it hasn’t been created yet ESC -> exit editing mode, go back to command mode
i -> enter editing mode
:w -> write (save document while you work on it)
:wq -> write and quit
ZZ -> write and quit (does the same as :wq)
:q -> quit vim
:e! -> discard all of the changes you have done

Editing mode

y -> copy text (yank)
yw -> copy a word
yy -> copy the entire line
double commands (yy) generally effect the whole line
5yy -> copy 5 lines
often you can pass a number to commands. i.e. 4w moves you 4 words forward.
p -> paste text
u -> undo action
U -> undo all actions on entire line

v -> enter the visual mode going down with your cursor you can highlight text in visual mode
0 -> go to the beginning of the line
$ -> go to the end of the line
w -> jump from word to word (., count as words)
W -> jump to the beginnig of the word, respecting white space separation
e -> move to the end of the word
b -> move back to the previous word
f/ -> moves you to the first /. / can be anything else, e.g. f" moves the cursor to the first quote.
; -> repeats the previous command (in case of f + /)

Command mode

x -> delete text where the cursor is while in command mode
ctrl + G -> get status of file
gg -> go to beginning of file
G -> go to end of file
/ -> search through file
:100 -> go to line 100 in file
500G -> go to line 100 in file (as well)
ctrl + f -> flip to next page
ctrl + b -> flip to previous page

dw -> delete a word after cursor
db -> delete a word before cursor
dd -> delete entire line

cc -> delete a line and put us in insert mode
cw -> a shortcut for dw + i to delete a word and go into insert mode
ctrl + d -> scroll a few paragraphs forward
ctrl + u -> scroll a few paragraphs backwards
H -> move to head text on screen
M -> move to middle of text on screen
L -> move to last line of text on screen

:help grep word -> search the help for word
* -> turns the word you are on into a search term. You can now hit n and move forward or N to go backwards.

:ls -> list all files in the buffer
:buffer 5 -> go to file with buffer with id 5
:b# -> switch to previously used buffer (switch windows)
:bd 5 -> delete buffer with if 5
->| -> switch between buffers

Tips and tricks:

  • Change your font size:

Place this in .gvimrc: set guifont=Monaco:h16

  • :help motion.txt contains all the motion options

Further learning resources: