Vim reference

Most of this is commands that I tend to forget because I don't use all the time, but are useful when needed.

Normal mode

gg=GAuto indent all the file
gfOpen file under the cursor
gdGo to the first appearance of the word in the function, useful to find variables declarations
gaDisplay character ascii value
Ctrl+W+FOpen file under the cursor in a new window
d/foo/Delete until foo
y/foo/eYank until foo end
guuTurn all line to lowercase
gUwTurn word to uppercase
3~Swap case of 3 characters
"\*pPastes the clipboard content (X11: primary selection)
"+yyCopy line to the clipboard
q:Open the command-line window
qaRecord macro in''a''
10@aExecute macro''a''10 times
z=Show spelling suggestions when spell checking is enabled
]pPaste line according to the identation level
KOpen man page of the word under the cursor
ci(Change the contents of ()
ya"Yank the whole string
di{Delete inner {} block
zzMove center of the screen to cursor line

Insert mode

Ctrl+NWord completion
Ctrl+X+LLine completion
Ctrl+X+KDictionary completion
Ctrl+X+FFile path completion
Ctrl+R=5*5Insert 25 into text (mini-calculator)
Ctrl+R++Pastes the clipboard content
Ctrl+OEnter normal mode and return to insert mode after executing one command
Ctrl+YCopy character form the line above
Ctrl+D or TShift left or right

Command-line mode

:set numberLine numbers on the left
:% !xxdConvert all to hexadecimal
:% !xxd -rConvert all from hexadecimal
:s%%//%%foo/greplace last searched pattern
:s/~/foo/g replace last replacement
:g/xpto/s/foo/bar/greplace''foo''by''bar''in lines where''xpto''exists
:g/foo/#display lines matching''foo''with line numbers
:g/foo/ddelete lines containing''foo''
:g/foo/.,.2j join the lines containing''foo''with the next 2 lines
:g/foo/normal AbarAppend''bar''to every line matching foo
:g/^/m0Reverses all lines
:args file1 file2Change the argument file list
:argdo %s/foo/bar/geExecute substitution for each file in the argument list
:windo editReopen all the windows files
:set spell spelllang=ptEnable spell checker
:set dictionary+=/usr/share/dict/wordsAdd dictionary
:hardcopyPrint file
:hardcopy > file.psPrint to postscript file

Visual mode

iwselect inner word
apselect paragraph
ibselect inner () block
2iBselect inner 2nd level of {} block
a[select [] block
i"select inner string

Visual block mode

I//ESCComment multiple lines


vim scp://user@host/directory/fileEdit files remotely
vim -o file1 file2 ...Open files in windows stacked
vim -O file1 file2 ...Open files in windows side by side
vim -p file1 file2 ...Open files in tabs
vim -Open stdin
vim +/pattern fileOpen file at pattern
vim +10 fileOpen file at line 10
vim --servername vimStart vim with client-server enable
vim --remote fileOpen the file in the remote vim
vim --remote-send Send keys to the remote vim