Cheat Sheet
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:
Modes
Esc – Return to NORMAL mode
Ctrl c – Exit INSERT mode
i – Enter INSERT mode ( Insert before the cursor )
I – Enter INSERT mode ( Insert at the begining of the line )
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
e a – 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
g e – Move to end of last word
g E – 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
z z – Center the cursor on the screen
z t – Positon the cursor to the top of the screen
z b – 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
g g – Go to first line, can be prefixed with a line number eg: 52gg
g d – Go to local definition
g D – Go to global definition
f # – Find next # character i.e. f a to find the next letter a on a line etc…
F # – Find previous # character
t # – Find next # character and put cursor after
T # – Find previous # 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 commands
: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
<leader> / – Comment out entire line
<leader> ? – Remove comment (entire line)
<leader> c d – Change working directory to the directory of the current document
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
F5 – make run
Shift F5 – make debug
Ctrl F5 – make clean
F12 – Convert [dos] to [unix]
Multi-file processing
Ctrl w s – Split window
Ctrl w v – Split window vertically
Ctrl w w – Switch windows
Ctrl w q – Quit window
Ctrl w = – Make all window the same size
Ctrl w x – Exchange current window with next one
Ctrl w l – Move cursor to the right window
Ctrl w h – Move cursor to the left window
Ctrl w j – Move cursor to the lower window
Ctrl w k – Move cursor to the upper window
Ctrl w L – Make current window full height on right
Ctrl w H – Make current window full height on left
Ctrl w J – Make current window full height on bottom
Ctrl w K – Make current window full height on top
Tab commands
:tabnew <file> – Open <file> in new tab
Ctrl w T – Move split window to its own tab
g t – Next tab or :tabn[ext]
g T – Previous tab or :tabp[revious]
w q – Quit window
:tabc[lose] – Close current tab
:tabm[ove] <num> – Move to tab <file>