|
JD's vi reference v1.0
Additions etc. are welcome at vi-ref@jeroenderks.com
|
| | | |
Moving around
command | description |
h | left |
j | down |
k | up |
l | right |
mx | set mark x |
e | end of word |
w | next word |
0 | begin of line |
^ | first word of line |
$ | end of line |
% | match ( { ['s |
'xx | go to mark x |
H | top of screen |
M | middle of screen |
L | end of screen |
Ctrl-D | half page down |
Ctrl-U | half page up |
Ctrl-F | page down |
Ctrl-B | page up |
:0<ENTER> | begin of file |
G | end of file |
|
Editing
command | description |
a | append (Insert mode) |
A | append at end of line (Insert mode) |
c | change (Replace mode) |
d | delete |
i | insert (Insert mode) |
I | insert at begin of line (Insert mode) |
o | new line below (Insert mode) |
O | new line above (Insert mode) |
p | paste after |
P | paste before |
r | change character |
u | undo/redo last command1 |
x | delete character |
X | delete previous character |
y | yank (copy) |
> | indent |
< | unindent |
~ | change case |
. | repeat last command |
Ctrl-6 | go to previous file2 |
ZZ | update (write if necessary) & exit |
|
1Sometimes, Ctrl-R is for redo
2Sometimes, Ctrl-Shift-6 is for go to previous file
|
|
Options
command | description |
:set all | show options |
:set ai | autoindent |
:set noai | no autoindent |
:set ic | ignore case in search |
:set noic | don't ignore case in search |
:set nu | show line numbers |
:set nonu | don't show line numbers |
:set sm | show match (for ( { ['s) |
:set nosm | don'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 |
n | continue last search forward |
N | continue last search backward |
|
|
|
|
|
File Commands
If followed by ! (exclamation) then force quit/write
even if changed file was not saved.
command | description |
:w | write |
:x | update (write if necessary) & exit |
:q | quit |
:wq | write & exit |
:n | next 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>/g | substitute all patterns <patt> with <expr> |
:s/<patt>/<expr>/gc | substitute all patterns <patt> with <expr> with confirmation |
:sh | spawn shell |
:!command | execute command in subshell |
:map <short> <cmd> | define shortcut <short> for command sequence <cmd> |
|
Examples
|
command | description |
dd | delete line |
2dd | delete two lines |
d2d | delete two lines |
:101,102d | delete lines from line numbers 101 to 102 |
de | delete to end of word |
dw | delete word |
d$ | delete to end of line |
d0 | delete to begin of line |
|
command | description |
:map = j0. | map '=' to repeat last command on beginning of next line |
:set ts=4 | set tabstops at every 4 characters |
:101,110s/abc/def/g | substitute all occurences of 'abc' with 'def' on lines 101 to 110 |
:%s/\/usr\/bin/\/usr\/local\/bin/g | substitute all occurences '/usr/bin' with '/usr/local/bin' throughout the file |
:%s/\(abc\)/X\1X/g | substitute all occurences of 'abc' with 'XabcX' throughout the file |
dH | delete to top of screen |
dM | delete to middle of screen |
dL | delete to end of screen |
xp | switch two characters |
|
Links
|