Some shortcuts for working with VIM, an open source text editor for the console. Available for Linux, Windows & Mac.
Smart movements
*and#search for the word under the cursor forward/backward.wto the next wordWto the next space-separated wordb/eto the begin/end of the current word. (B/Efor space separated only)gg/Gjump to the begin/end of the file.%jump to the matching { .. } or ( .. ), etc..{/}jump to next paragraph.'.jump back to last edited line.g;jump back to last edited position.
Quick editing commands
Iinsert at the begin.Aappend to end.o/Oopen a new line after/before the current.v/V/Ctrl+Vvisual mode (to select text!)Shift+Rreplace textCchange remaining part of line.
Combining commands
Most commands accept a amount and direction, for example:
cW= change till end of word3cW= change 3 wordsBcW= to begin of full word, change full wordciW= change inner word.ci"= change inner between „..“ci(= change text between ( .. )ci<= change text between < .. > (needsset matchpairs+=<:>in vimrc)4dd= delete 4 lines3x= delete 3 characters.3s= substitute 3 characters.
Useful programmer commands
rreplace one character (e.g.rdreplaces the current char withd).~changes case.Jjoins two lines- Ctrl+A / Ctrl+X increments/decrements a number.
.repeat last command (a simple macro)==fix line indent>indent block (in visual mode)<unindent block (in visual mode)
Macro recording
- Press
q[ key ]to start recording. - Then hit
qto stop recording. - The macro can be played with
@[ key ].