start vim
vim [file]...
start vim in read only mode
vim -R [file]...
view [file]...
pipe output of another command to vim
ls -la | vim -
open multiple files in horizontal panes
vim -o [file]...
open multiple files in vertical panes
vim -O [file]...
edit remote file via scp
vim scp://user@host//path

insert mode

go to command mode
auto complete
paste from selection clipboard
control-r, *
paste from system clipboard
control-r, +
more general
control-r, [register]
execute a single command in normal mode, then return to insert mode

visual mode

copy selected block
delete selected block
paste block
jump to other end of selection

command mode

moving around

basic movement
h left
j down
k up
l right
viewport based movement
L      jump to lowest line in viewport
M      jump to middle line in viewport
H      jump to highest line in viewport
ctrl-E move viewport up a line
ctrl-Y move viewport down a line
ctrl-U move viewport up half a screen
ctrl-D move viewport down half a screen
ctrl-F <pgup>
ctrl-B <pgdn>
pgup   move viewport up one screen
pgdn   move viewport down one screen
word based movement
w next word [a-z0-9_]
W next word \S
b back one word [a-z0-9_]
B back one word \S
e next word end [a-z0-9_] 
E next word end \S
line based movement
0     line start
^     line start
$     line end, [n]$ for nth line
<END> line end, [n]$ for nth line
}     next blank line
{     previous blank line
:[n]  jump to line [n]
[n]G  jump to line [n]
f[c]  jump forward to character [c], [n]f[c] for nth match
F[c]  jump backward to character [c], [n]f[c] for nth match
t[c]  jump forward to character before [c], [n]f[c] for nth match
T[c]  jump backward to character before [c], [n]f[c] for nth match
file based movement
% jump to matching parenthesis for selected or closest ()[]{}
gg   move to first line
G    move to last line
[p]% move to [p] percent of file
history based movement
``     move back to position preceding the last jump
ctrl-O go back in jump history (older)
ctrl-I go forward in jump history (newer)
:jump  show jump history
m[a-z] mark a local position (current file)
m[A-Z] mark a global position (any open file)
'[a-z] jump to mark, beginning of line
`[a-z] jump to mark, marked line & column
`'     jump to line before jump, beginning of line
`"     jump to position when last editing file
`[     jump to start of last change
`]     jump to start of last change
:marks list marks


scroll one line (up/down)
ctrl + Y
ctrl + E
go to insert mode on cursor
go to insert mode on line start
go to visual mode (lines)
v           lines starting at cursor
V           whole lines starting at current line
ctrl + v    columns
add new line after current and edit it (insert mode)
add new line before current and and edit it (insert mode)
delete line from here and go to insert mode
delete line and go to insert mode
delete one line
delete n lines
delete from begin of line to here
delete from here to end of line
delete from here to end of word
delete focused word
diw    whitespace excluded
daw    whitespace included
delete inbetween quotes
delete block, valid characters: [], (), {}
delete sentence ending with "."
deleting single characters
x    delete character under cursor
X    delete character before cursor
[n]x delete [n] characters (forward)
[n]X delete [n] characters (backwards)
copy one line (where the cursor is)
copy from cursor to end of line
paste before cursor
paste after cursor
paste [n] times
paste from system clipboard
<shift> + insert
letter toggle case
indent current line
indent n lines
shift left until end of file
increment first number to the right
decrement first number to the right
repeat last (change) command
execute multiple commands in a row
:[cmd1] | [cmd2]

working with files / buffers

force quit
save file and quit
new empty buffer
open file in editor (new buffer)
:e(dit) [file]         warn if currently open file has changes
:e(dit)! [file]        silently discard changes in currently open file
:hide e(dit) [file]    ignore changes in currently open file and open a new buffer
save file
save as
:w(rite) [file]
append to file (must exist)
:w(rite) >> [file]
change default file for write command
:file [file]      # do not writeback to disk
:saveas [file]    # writeback to disk
show open files / buffers with indexes
switch to open file / buffer
:b [index]
cycle buffers
:b <tab>...
next unread buffer
next buffer
previous buffer
close buffer
:bd [index]
wipeout current buffer (no save warning)
show history
history: jumpt to previous edit location
history: jumpt to next edit location

search and replace


find other matches of word under cursor
* forward search exact match
 # backward search exact match
g* forward search partial match
g# backward search partial match
reverse search
next search result
previous search result
case insensitive search
case sensitive search
find slash forward
find with wildcard matching
character class
any character
literal dot
word boundary


replace first occurrence on current line
:s /search/replace/
replace first occurrence on any line
:%s /search/replace/
replace all occurrences on any line
:%s /search/replace/g
replace confirmation mode
:%s /search/replace/c
refer to capturing group 0 (entire line)
:%s /search/pre\0post/
refer to first capturing group
:%s /before\(keep\)after/pre\1post/

command ranges

line [n] to [m]
current line
current line + [n] more lines
current line to end of document
start of document to current line
current line up to line matching [regex]
from line matching [regex1] up to line matching [regex2]
example: delete lines 3-5
:3,5d i
example: yank lines 3-5
example: write line [n] to [m] to a new file
:[n],[m] write [file]
example: replace on lines [n] up to [m]


execute command on all lines matching a regex
execute command on all lines NOT matching a regex
delete all lines matching a regex
copy all lines matching a regex to the end of the document
move all lines matching a regex to the end of the document
move all lines matching a regex to line [n]
on lines matching [regex] search for [query] and replace with [replacement]
example: put a newline before every line
g/^/pu = \"\n\"
example: delete all empty lines
example: delete all blank lines

shell command

run shell command (e.g. ls)
run command and insert command output into vim
:read ![cmd]
run command and insert command output after line number [n]
:[n]read ![cmd]
run command and insert command output at start of document
:0read ![cmd]
run command and insert command output at end of document
:$read ![cmd]


open a file in a new tab
:tabedit [file]
open file browser in new tab
next tab
previous tab
open tab number [n]
close tab
close all other tabs
list open tabs
open vim with multiple files in tabs
vim -p [file]...

split screen

split editor horizontal
Ctrl-W, s
split editor vertical
Ctrl-W, v
split and open file
:sp     [file]
:split  [file]
:vsp    [file]
:vsplit [file]
close all other split panes
open file browser (split screen)
open terminal
vim cycle split panes
Ctrl-W, direction
ctrl w, w
flip splits
ctrl-w, r
close current window / tab
ctrl-w, c
use full window height
ctrl-w _
use full window width
ctrl-w |
reset window widths & heights
ctrl-w =
increase pane size
ctrl-w +
decrease pane size
ctrl-w -
move between panes
ctrl w-f    # move left
ctrl w-j    # move down
ctrl w-k    # move up
ctrl w-l    # move right
reorder panes
ctrl w-F    # move left
ctrl w-J    # move down
ctrl w-K    # move up
ctrl w-L    # move right
quit (all panes)
save all panes
write all panes and quit


dump all registers
special registers
*    selection clipboard
+    system clipboard
yank to register
cut to register
paste from register
echo register [r] contents
:echo @[r]
store a string in a register
let @a='test'
copy between registers
:let @[destination] = @[source]
example: copy register "a" to the system clipboard
:let @+ = @a
execute command stored in register "r"
print filename
:echo @%
:!echo %


config file (all vims)
config file (gvim only)
disable plugin for highlighting matching parenthesis
:let loaded_matchparen = 0
disable highlighting matching parenthesis after plugin has been loaded
show line numbers
:set number
case insensitive searching
:set ignorecase
case insensitive unless any caps in query
:set smartcase
highlighting enabled
:syntax on
highlight matches as you type
:set incsearch
highlight search matches
:set hlsearch
turn of search highlighting (current search)
turn of search highlighting (permanently)
:set nohlsearch
show incomplete commands in lower right
:set showcmd
show multiple matches on tab completion
:set wildmenu
tabs are [n] spaces
:set tabstop=[n]
indent with [n] spaces per level
:set shiftwidth=[n]
backspace and space wrap line endings (normal mode)
:set whichwrap=b,s
left and right keys wrap line endings (normal mode)
:set whichwrap=<,>
left and right keys wrap line endings (insert mode)
:set whichwrap=[,]
display tabs and trailing whitespace with custom characters
:set listchars=tab:>-,trail:-
wrap long lines
:set wrap
do no wrap long lines
:set nowrap
do not create backup file
:set nobackup
do not create swap files
set noswapfile
don't create un~ files
set noundofile
don't auto indent whitespace
filetype indent off
do not show toolbar (gvim)
:set guioptions-=T
set path to open file as terminal title
:set title
write files back to disk before running commands
:set autowrite
select colorscheme
:colorscheme torte
open new horizontal splits below open current
:set splitbelow
open new vertical splits on the right side
:set splitright
font selector
:set guifont=*
get current font string
:set gfn?
set font
:set guifont=courier
set font and size (gvim linux)
:set guifont=courier\ 16
:set guifont=Ubuntu\ Mono\ 12


view diff between 2 files
vimdiff [file-a] [file-b]
gvimdiff [file-a] [file-b]
more info

getting help

show help pages
close help
show command index
:help index
show help for specific command
:help [cmd]
show help for vim command line argument (flag)
:help -[flag]
show help for key combination (e.g. CTRL-A) in command mode
:help [key]
show help for key combination (e.g. CTRL-A) in insert mode
:help i_[key]
show help for key combination (e.g. CTRL-A) in visual mode
:help v_[key]

navigation in help

follow link

vim documentation files