You are on page 1of 5

BASIC VI COMMANDS

To Start vi
1. 2. vi filename vi -r filename Create or Edit filename starting at line 1 Recover filename that was being edited when system crashed

To Exit vi
1. 2. &. '. :x ret!rn" :w% ret!rn" :% ret!rn" :%( ret!rn" #!it vi$ writing o!t modified file to file named in original invocation #!it vi$ writing o!t modified file to file named in original invocation #!it or exit vi #!it vi even tho!gh latest changes have not been saved for this vi call

)oving the c!rsor


1. 2. &. * or ret!rn" )ove c!rsor down one line )ove c!rsor !. one line )ove c!rsor left one line )ove c!rsor right one line )ove c!rsor to start of c!rrent line0the one with the arrow2 3. 5. 4 w )ove c!rsor to end of the c!rrent line )ove c!rsor to beginning of next word +or down-arrow, -+or !.-arrow, h or bac-s.ace" +or left-arrow, l or s.ace"+or right-arrow, '. /01ero2

Basic vi commands

6. 7. 9. 1/.

b :/ ret!rn" or 18 :n ret!rn"or n8 :4 ret!rn"or 8

)ove c!rsor bac- to beginning of .receding word )ove c!rsor to first line in file )ove c!rsor to line n in file )ove c!rsor to last line in file

Screen )ani.!lation
1. 2. &. '. 3. 5. :f :b :d :! :l :r )ove forward one screen )ove bac-ward one screen )ove down0forward2 one half screen )ove !.0bac-2one half sreen Redraws the screen Redraws the screen$removing the deleted lines

;dding$Changing$<eleting the text


1. ! =ndo whatever yo! *!st did0a sim.le toggle2

>nserting or ;dding text


1. 2. &. '. 3. 5. i > a ; o ? >nsert text before c!rsor$!ntil esc"hit >nsert text at beginning of c!rrent line$!ntil esc"hit ;..end text after c!rsor$!ntil esc"hit ;..end text to end of c!rrent line$!ntil esc"hit ?.en and .!t text in a new line below c!rrent line$!ntil esc"hit ?.en and .!t text in a new line above c!rrent line$!ntil esc"hit

Basic vi commands

Changing the text


1. 2. &. r R cw Re.lace single character !nder c!rsor0no esc"needed2 Re.lace characters$starting with c!rrent c!rsor .osition$!ntil esc"hit Change the c!rrent word with new text$starting with the character !nder c!rsor$!ntil esc"hit '. 3. 5. 6. c@w c cc @cc or c@c Change @ words beginning with the character !nder c!rsor$!ntil esc"hit change0re.lace2the characters in the c!rrent line$!ntil esc"hit change0re.lace2the characters in the c!rrent line$sto..ing when esc"hit change0re.lace2the next @ lines$starting with the c!rrent line$sto..ing when esc"hit

<eleting the text


1. 2. &. '. 3. 5. 6. x @x dw d@w < dd @dd or d@d <elete single character !nder c!rsor <elete @ characters$ starting with character !nder c!rsor <elete the single word beginning with character !nder c!rsor <elete @ words beginning with character !nder c!rsor <elete the remainder of the line$starting with c!rrent c!rsor .osition <elete entire c!rrent line <elete @ lines beginning with the c!rrent line Basic vi commands

C!tting and .asting the text


1. 2. &. yy @yy or y@y . Co.y 0yan-$c!t2 the c!rrent line into b!ffer co.y0yan-$c!t2 the next @ lines$incl!ding the c!rrent line$ into the b!ffer .!t0.aste2 the lines in the b!ffer into the text after the c!rrent line

Searching the text


1. 2. &. '. Astring Bstring n @ Search forward for occ!rence of string in text Search bac-ward for occ!rence of string in text )ove to next occ!rence of search string )ove to next occ!rence of search string in o..osite direction

<etermining line n!mbers


1. 2. &. :.C :C :g Ret!rns line n!mber of c!rrent line at bottom of screen Ret!rns the total n!mber of lines at bottom of the screen Drovides the c!rrent line n!mber$ along with the total n!mber of lines$in the file at the bottom of the screen

Saving and reading files


1. :r filename ret!rn" Read file named filename and insert after c!rrent line0the line with arrow2

Basic vi commands

2. &. '. 3.

:w ret!rn" :w newfile ret!rn" :12$&3w smallfile ret!rn" :w( .revfile ret!rn"

Erite c!rrent contents to a file named in original vi call Erite c!rrent contents to a new file named newfile Erite the contents of the line n!mbered 12 thro!gh &3 to a new file named smallfile Erite c!rrent contents over a .re-existing file named .revfile

Basic vi commands

You might also like