If for a key combination, something like nx, the n is missing one is assumed. E.g. to replace only a single character right under the cursor position in normal mode hit s followed by the replacement (can be more characters but only the first will be replaced). For most commands the optional number right before the command is somewhat a repeater to instruct how often the following should be executed.
Essentials
insert at cursor i
insert at start of line I
.. end of line A
leave insert mode <ESC>
replace next (n) char(s) incl. cursor ns
repeat last (n) command(s) n.
insert n new lines after this no
insert n new lines before this nO
delete next n lines with current ndd
delete until end of line D
paste from cursor onwards nP
past after cursor np
Search and Replace
- Change to normal (navigation) mode with <ESC>
- Search (Wraped around at end of file):
Search STRING forward : / STRING.
Search STRING backward: ? STRING. - Repeat search: n
Repeat search in opposite direction: N (SHIFT-n) - Replace: Same as with sed, Replace OLD with NEW:
First occurrence on current line: :s/OLD/NEW
Globally (all) on current line: :s/OLD/NEW/g
Between two lines #,#: :#,#s/OLD/NEW/g
Every occurrence in file: :%s/OLD/NEW/g
References:
Tony Chen’s vi-manual
Felix Gers’s manual
vi reference on pages.de
RefCard on digilife.be (pdf)







