Index

vim

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

insert mode

go to command mode
esc
paste from system clipboard
control-r, +
more general
control-r, [register]

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
paste from system clipboard
<shift> + insert
undo
u
redo
ctrl-r
jump to line 10
:10
jump to end of file
G
increment first number to the right
ctrl-a
decrement first number to the right
ctrl-x

working with files / buffers

save file
:w
quit
:q
force quit
:q!
save file and quit
:x
new empty buffer
:new
:vnew
open file in editor (new buffer)
:o [file]
show open files / buffers with indexes
:ls
switch to open file / buffer
:b [index]
cycle buffers
:b <tab>...
next bufer
:n
previous buffer
:p
execute multiple commands in a row
:[cmd1] | [cmd2]

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

registers

dump all registers
:display
:reg
:di
echo register [r] contents
:echo @[r]
copy between registers
:let @[destination] = @[source]
example: copy register "a" to the system clipboard
:let @+ = @a

config

config file (all vims)
.vimrc
config file (gvim only)
.gvimrc
show line numbers
:set number

" highlighting enabled
syntax on
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 create swap files
set noswapfile
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

mapping keys

hello world example
map - :echo 'Current time is ' . strftime('%c')<CR>
map <F12> :echo 'Current time is ' . strftime('%c')<CR>

" copy and paste example (like windows)
vmap <C-c> "+yi
vmap <C-x> "+c
vmap <C-v> c<ESC>"+p
imap <C-v> <ESC>"+pa

" Make shift-insert paste like in Xterm
map <S-Insert> <MiddleMouse>
map! <S-Insert> <MiddleMouse>
list key mappings (overrides)
map  # normal, visual, select & operator pending
map! # insert & command-line
nmap # normal mode
imap # insert mode
vmap # visual & select
remove keymapping
unmap  [key]
unmap! [key]
nunmap [key]
iunmap [key]
vunmap [key]

https://vim.fandom.com/wiki/Mapping_keys_in_Vim_-_Tutorial_(Part_1)

documentation

http://vimdoc.sourceforge.net/htmldoc/vimindex.html
https://vim.fandom.com/wiki/Accessing_the_system_clipboard