vim file | edit the file in the current window |
gvim file | edit the file in graphical mode (other window + menubar) |
vim +r123 file | edit the file with the cursor positioned on line 123 |
vim -b file | edit foobar in binary more (i.e. set noexpandtab , textwidth=0 , nomodeline , and binary ) |
vim -o file1 file2 file3 | start vim with each file loaded in a horizontal window |
vim -O file1 file2 file3 | start vim with each file loaded in a vertical window |
vim -o4 file1 file2 | start vim with four horizontal windows |
vim -O4 file1 file2 | start vim with four vertical windows |
vim -R file | open the file in read only mode |
Undo/redo
U
:u[ndo] | undo |
CtrlR
:red[o] | redo |
U | undo latest changes on the line |
Cut ’n paste
V
move the cursor at the end of the region to copy Y | copy characters |
ShiftP | paste before the cursor |
P | paste after the cursor |
Search
/ | search forward |
? | search backward |
* | search forward for the word under the cursor |
# | search backward for the word under the cursor |
N | next match |
ShiftN | previous match |
:set hlsearch | enable search result highlighting |
:set noh[lsearch] | disable search result highlighting |
:nohlsearch | hide the current search result highlighting |
Windows
CtrlWS | split the window horizontally in two |
CtrlW←
CtrlWCtrlH CtrlWH | go to the left window |
CtrlW→
CtrlWCtrlL CtrlWL | go to the right window |
CtrlW↓
CtrlWCtrlJ CtrlWJ | go to the window below |
CtrlW↑
CtrlWCtrlK CtrlWK | go to the window above |
Numbering
:set number
:set nu | display line numbers |
:set nonumber
:set nonu | undisplay line numbers |
:set nu! | toggle the display of line numbers |
Colours
:set background=dark | set the syntax highlight colours corresponding to a dark background |
:set background=light | set the syntax highlight colours corresponding to a light background |
:syntax on | enable syntax highlighting (the default colours are applied) |
:syntax enable | enable syntax highlighting (the colours defined by :highlight are kept) |
:syntax off | disable syntax highlighting |
Miscellaneous
% | move to matching brace or keyword |
the configuration file is
$HOME/.vimrc
.