Index

Starting vim

start vim
vim
pipe output of another command to vim
ls -la | vim -
edit remote file via scp
vim scp://user@host//path

config

show line numbers
:set number
highlight search matches
:set hlsearch
turn of search highlighting (current search)
:nohlsearch
turn of search highlighting (permanently)
:set nohlsearch
wrap long lines
:set wrap
do no wrap long lines
:set nowrap
do not create backup file
:set nobackup
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

insert mode

go to command mode
esc

command mode

editing

go to insert mode on cursor
i
add new line after current and edit it (insert mode)
o
add new line before current and and edit it (insert mode)
O
delete one line
dd
delete n lines
d[n]d
copy one line (where the cursor is)
yy
copy from cursor to end of line
y$
paste before cursor
P
paste after cursor
p
undo
u
redo
<ctrl> + r
jump to line 10
:10
jump to end of file
G

working with files / buffers

save file
:w
quit
:q
force quit
:q!
save file and quit
:x
open file in editor (new buffer)
:o [file]
show open buffers with indexes
:ls
switch to open buffer
:b [index]

search and replace

search

find
/query
reverse search
?query
next search result
n
previous search result
N
find slash forward
/\/
find with wildcard matching
/.*
/.\+
character class
/[^a-z]

replace

replace first occurrence on line
:%s /search/replace/
replace all occurrences on 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/

split screen

split editor horizontal
Ctrl-W + s
:sp
:split
split editor vertical
Ctrl-W + v
:vsp
:vsplit
split and open file
:sp     [file]
:split  [file]
:vsp    [file]
:vsplit [file]
vim cycle split panes
Ctrl-W + direction
ctrl w w