Basic vi Commands

Back to Computer Technology > Tutorials

by Marisa Luvisetto
2000-12-20
 

BASIC MOVEMENT/DELETE COMMANDS
Command Item Forward Backward Repeat (1)
move character $\rightarrow$ $\leftarrow$ n
delete   x X y
move word start (2) w b n
  word end e   n
delete word dw db y
move line $ 0 n
delete   d$ d0 y
move file G 1G n
delete   dG d1G y
move paragraph } { n
delete   d} d{ y
Absolute/Relative Direction
Command Item OpCode Action Repeat (1)
go to line :line_no absolute line no. n
delete range :n1,n2d absolute line range n1<n2 n
    :.,+nd relative line range form here to n n
go to lines $:.\pm n$ move +n or -n lines from here n
delete lines $:.\pm n$d delete one line at +n or -n lines from here n
Using Markers
Command Item OpCode Action Repeat (1)
go to marker `a (3) move from here to marker a n
    'a (4) move from here to line marked a n
delete marker range d`a (3) delete from here to marker a n
    d'a (4) delete from here to line marked a n
(1) - repeat character is . (dot)
(2) - use uppercase codes W, E, B for whole words
(3) - use backquote to select marked position
(4) - use quote to select marked line

BASIC SEARCH OPERATORS
Item Forward Backward Action Repeat Count
string / ? search string in file (1) n
.* / ? use wild match search n
character f F search char in line (2) y
Repeat Search Operators
Item Operator Action Repeat Count
string n same direction of previous search n
  N opposite direction of previous search n
character ; same direction of previous search y
  , opposite direction of previous search y
Setup Search Modifiers
setup Action
:se nows inhibit circular search and stop when EOF or BOF met
:se ic ignore case of searched string, always match case of searched char
(1) - search strings are regular expressions
(2) - integer repeat count is prefixed to search operator
n.b. - search operator is prefixed to search item

BASIC SUBSTITUTE COMMANDS
Command Action Repeat count
r overstrike one single character y
R overstrike chars up to <esc> y
cc replace line up to <esc> y
cw replace word forward up to <esc> y
cb replace word backward up to <esc> y
s substitute char up to <esc> y
:s/old/new/gc replace all occurence of regular expression old  
  with string new in current line with confirm n
:50,100 s/old/new/gc as above on line range n
:s unconditionally repeat previous string replace n
:sc repeat previous string replace with confirm n
n.b. - use :se noic to force case match
n.b. - use :se nu to display line numbers

BASIC RESTORE/UNDO COMMANDS
Command Action
:e! reread file and erase all changes
u undo last change
U restore current line
xp exchange characters
"1p restore buffer 1 after (1)
"1P restore buffer 1 before
"2p restore buffer 1 after
"2P restore buffer 1 before
(1) - buffer range is 1:9, repeat operator (dot) on restore buffer 1
restores delete lines in reverse order


BASIC GENERAL COMMANDS
Command Action
Q switch from vi to ex
vi switch from ex to vi
^L refresh screen
:# print current line with line no.
:.= print line no. of current line
:= print line no. of last line in current file
:se nu set line no.
:se noic set case match
:se all list all editor parameters
:se param? list current value of parameter
/^L move over <FF>, the eve section delimiter
  to insert ^F type <ctrl>L