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=G | Auto indent all the file |
gf | Open file under the cursor |
gd | Go to the first appearance of the word in the function, useful to find variables declarations |
ga | Display character ascii value |
Ctrl+W+F | Open file under the cursor in a new window |
d/foo/ | Delete until foo |
y/foo/e | Yank until foo end |
guu | Turn all line to lowercase |
gUw | Turn word to uppercase |
3~ | Swap case of 3 characters |
"\*p | Pastes the clipboard content (X11: primary selection) |
"+yy | Copy line to the clipboard |
q: | Open the command-line window |
qa | Record macro in''a'' |
10@a | Execute macro''a''10 times |
z= | Show spelling suggestions when spell checking is enabled |
]p | Paste line according to the identation level |
K | Open man page of the word under the cursor |
ci( | Change the contents of () |
ya" | Yank the whole string |
di{ | Delete inner {} block |
zz | Move center of the screen to cursor line |
Insert mode
Ctrl+N | Word completion |
Ctrl+X+L | Line completion |
Ctrl+X+K | Dictionary completion |
Ctrl+X+F | File path completion |
Ctrl+R=5*5 | Insert 25 into text (mini-calculator) |
Ctrl+R++ | Pastes the clipboard content |
Ctrl+O | Enter normal mode and return to insert mode after executing one command |
Ctrl+Y | Copy character form the line above |
Ctrl+D or T | Shift left or right |
Command-line mode
:set number | Line numbers on the left |
:% !xxd | Convert all to hexadecimal |
:% !xxd -r | Convert all from hexadecimal |
:s%%//%%foo/g | replace last searched pattern |
:s/~/foo/g | replace last replacement |
:g/xpto/s/foo/bar/g | replace''foo''by''bar''in lines where''xpto''exists |
:g/foo/# | display lines matching''foo''with line numbers |
:g/foo/d | delete lines containing''foo'' |
:g/foo/.,.2j | join the lines containing''foo''with the next 2 lines |
:g/foo/normal Abar | Append''bar''to every line matching foo |
:g/^/m0 | Reverses all lines |
:args file1 file2 | Change the argument file list |
:argdo %s/foo/bar/ge | Execute substitution for each file in the argument list |
:windo edit | Reopen all the windows files |
:set spell spelllang=pt | Enable spell checker |
:set dictionary+=/usr/share/dict/words | Add dictionary |
:hardcopy | Print file |
:hardcopy > file.ps | Print to postscript file |
Visual mode
iw | select inner word |
ap | select paragraph |
ib | select inner () block |
2iB | select inner 2nd level of {} block |
a[ | select [] block |
i" | select inner string |
Visual block mode
I// ESC | Comment multiple lines |
Options
vim scp://user@host/directory/file | Edit 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 file | Open file at pattern |
vim +10 file | Open file at line 10 |
vim --servername vim | Start vim with client-server enable |
vim --remote file | Open the file in the remote vim |
vim --remote-send | Send keys to the remote vim |