" /> JD's vi reference v1.0
Google
 

JD's vi reference v1.0

Additions etc. are welcome at vi-ref@jeroenderks.com

Moving around

command   description   
hleft
jdown
kup
lright
mxset mark x
eend of word
wnext word
0begin of line
^first word of line
$end of line
%match ( { ['s
'xxgo to mark x
Htop of screen
Mmiddle of screen
Lend of screen
Ctrl-Dhalf page down
Ctrl-Uhalf page up
Ctrl-Fpage down
Ctrl-Bpage up
:0<ENTER>begin of file
Gend of file

Editing

command   description   
aappend (Insert mode)
Aappend at end of line (Insert mode)
cchange (Replace mode)
ddelete
iinsert (Insert mode)
Iinsert at begin of line (Insert mode)
onew line below (Insert mode)
Onew line above (Insert mode)
ppaste after
Ppaste before
rchange character
uundo/redo last command1
xdelete character
Xdelete previous character
yyank (copy)
>indent
<unindent
~change case
.repeat last command
Ctrl-6go to previous file2
ZZupdate (write if necessary) & exit

1Sometimes, Ctrl-R is for redo
2Sometimes, Ctrl-Shift-6 is for go to previous file

Options

command   description   
:set allshow options
:set aiautoindent
:set noaino autoindent
:set icignore case in search
:set noicdon't ignore case in search
:set nushow line numbers
:set nonudon't show line numbers
:set smshow match (for ( { ['s)
:set nosmdon't show match
:set ts=#set tabstops at #
:set sw=#set shift width at #
:set wm=#set wrapmargin at #

Options

command   description   
/<expr>search forward for <expr>
?<expr>search backward for <expr>
/repeat last search forward
?repeat last search backward
ncontinue last search forward
Ncontinue last search backward
 
 
 
 
 

File Commands

If followed by ! (exclamation) then force quit/write
even if changed file was not saved.
command   description   
:wwrite
:xupdate (write if necessary) & exit
:qquit
:wqwrite & exit
:nnext file
:e <filename>edit file
:r <filename>insert file <filename>
 

Miscellaneous Commands



command   description   
:s/<patt>/<expr>substitute pattern <patt> with <expr>
:s/<patt>/<expr>/gsubstitute all patterns <patt> with <expr>
:s/<patt>/<expr>/gcsubstitute all patterns <patt> with <expr> with confirmation
:shspawn shell
:!commandexecute command in subshell
:map <short> <cmd>define shortcut <short> for
command sequence <cmd>

Examples

command   description   
dddelete line
2dddelete two lines
d2ddelete two lines
:101,102ddelete lines from line numbers 101 to 102
dedelete to end of word
dwdelete word
d$delete to end of line
d0delete to begin of line
command   description   
:map = j0.map '=' to repeat last command on beginning of next line
:set ts=4set tabstops at every 4 characters
:101,110s/abc/def/gsubstitute all occurences of 'abc' with 'def' on lines 101 to 110
:%s/\/usr\/bin/\/usr\/local\/bin/gsubstitute all occurences '/usr/bin' with '/usr/local/bin' throughout the file
:%s/\(abc\)/X\1X/gsubstitute all occurences of 'abc' with 'XabcX' throughout the file
dHdelete to top of screen
dMdelete to middle of screen
dLdelete to end of screen
xpswitch two characters

Links