Skip to contentSkip to footer
html4 darkhtml4 light

Cheat Sheet - Work-In-Progress

VIM (vi improved) is an editor that has been ported to many systems: Linux, RISC OS, Windows etc...

Below are some useful key shortcuts & commands (blue letters are lowercase):


Modes:
Esc  —  Return to NORMAL mode
Ctrl + c  —  Exit INSERT mode
i  —  Enter INSERT mode (see below)
I  —  Enter INSERT mode (see below)
v  —  Enter VISUAL mode
V  —  Enter VISUAL LINE mode
Ctrl + v  —  Enter VISUAL BLOCK mode

Insert:
i  —  Insert before the cursor
I  —  Insert at the begining of the line
o  —  Insert new line below
O  —  Insert new line above
a  —  Insert at current cursor position
A  —  Insert at end of line
ea  —  Insert at end of word
Ctrl + w  —  Delete word before cursor
Ctrl + j  —  Add line break at cursor
Ctrl + t  —  Indent
Ctrl + d  —  Unindent
Ctrl + n  —  Auto complete next match
Ctrl + p  —  Auto complete previous match

Movement:
w  —  Move to start of next word
W  —  Move to start of next word with punctuation
b  —  Move to start of last word
B  —  Move to start of last word with punctuation
e  —  Move to end of next word
E  —  Move to end of next word with punctuation
ge  —  Move to end of last word
gE  —  Move to end of last word with punctuation
H  —  Move to the top of the screen
M  —  Move to thge middle of the screen
L  —  Move to the bottom of the screen
zz  —  Center the cursor on the screen
zt  —  Positon the cursor to the top of the screen
zb  —  Positon the cursor to the bottom of the screen
Ctrl + u  —  Move cursor and screen up 1/2 a page
Ctrl + d  —  Move cursor and screen down 1/2 a page
gg  —  Go to first line, can be prefixed with a line number eg: 52gg
gd  —  Go to local definition
gD  —  Go to global definition
fx  —  Find next x character
Fx  —  Find previous x character
tx  —  Find next x character and put cursor after
Tx  —  Find previous x character and put cursor after
;  —  Repeat last t f T F search
,  —  Repeat last t f T F search backwards
G  —  Go to last line
$  —  Go to end of line
g_  —  Go to last non-blank char of line
0  —  Go to begining of line
^  —  Go to first non-blank char of line
}  —  Go to next empty line (down)
{  —  Go to previous empty line (up)
%  —  Go to matching {} [] ()

Search and replace:
n  —  Repeat search in same direction
N  —  Repeat search in opposite direction
:%s/search/replace/g  —  Replace all search with replace throughout file
:%s/search/replace/gc  —  Replace all search with replace throughout file with confirmation
:noh[lsearch]  —  Remove highlighting of search matches

Multi-file search:
:vim[grep] /string/ {`{file}`}  —  Search for string in files (:vim /foo/ **/*)
:cn[ext]  —  Next match
:cp[revious]  —  Previous match
:cope[n]  —  Open list of matches
:cll[ose]  —  Close list of matches

Keys specific to my VIM configuration:
Space/  —  Comment out entire line
Space?  —  Remove comment (entire line)
F2  —  Open netrw in right split
Shift + F2  —  Open netrw full buffer
F3  —  Toggle indent lines on/off
Shift + F3  —  Toggle spell on/off
F4  —  Re-indent entire buffer
F12  —  Convert [dos] to [unix]