Categorized | Tip

vi Quick Reference

This table is taken from Sun Microsystems' User's Guide: Getting Started (.

		 Starting vi 

vi filename 		 open or create file 

vi +18 filename 		 open to line 18 

vi +/"mustard" filename 		 open file to first occurence of    ``mustard" 

vi -r filename 		  recover crashed file 

view filename 		 open file read-only 

Cursor Commands 

h 		 move left 

j		 move down 

k 		 move up 

l 		 move down 

w 		 move right one word 

W 		 move right one word (past punctuation) 

b 		 move left one word 

B 		 move left one word (past punctuation) 

Return 		 move down one line 

Back Space 		 move left one character 

Space Bar 		 move right one character 

H 		 move to top screen 

M 		 move to middle of screen 

L 		 move to bottom of screen 

Ctl-F 		 scroll forward one screen 

Ctrl-D 		 scroll forward one-half screen 

Ctrl-B 		 scroll backward one screen 

Ctrl-U 		 scroll backward one-half screen 

Insterting Characters and Lines 

a 		 insert characters to right of cursor 

A 		 insert characters to right of cursor, at end of line 

i 		 insert characters to left of cursor 

I 		 insert characters to left of cursor, at beginning of line 

o 		 insert line below cursor 

O 		 insert line above cursor 

Changing Text 

cw 		 change word (or part of word right of cursor) 

cc 		 change line 

C 		 change part of line to right of cursor 

s 		 substitute string for character under cursor 

r 		 replace character under cursor with one other character 

r-Return 		 break line 

J 		 join current line and line below 

xp 		 transpose character at cursor & character to right 

  		 change case of letter (upper or lower) 

u 		 undo previous command 

U 		 undo all changes to line 

:u 		 undo previous last-line command 

Deleting Text 

x 		 delete character 

dw 		 delete word (or part of word to right of cursor) 

dd 		 delete line 

D 		 delete part of line to right of cursor 

:5,10 d 		 delete lines 5-10 

Copying and Moving Text 

yy 		 yank or copy line 

Y 		 yank or copy line 

dd 		 delete line 

p 		 put yanked or deleted line below current line 

P (upper case) 		 put yanked or deleted line above current line 

:1,2 co 3 		 copy lines 1-2 and put after line 3 

:4,5 m 6 		 move lines 4-5 and put after line 6 

Setting Line Numbers 

:set nu 		 show line numbers 

:set nonu 		 hide line numbers 

Finding a Line 

G 		 go to last line of file 

21G 		 go to line 21 

Searching and Replacing 

/string/ 		 search for string 

$?$string$?$ 		 search backwards for string 

n 		 find next (or previous) occurence of string 

:g/search/s//replace/gc 		 search and replace,     consult at each occurence 

Clearing the Screen 

Ctrl-L 		 clear scrambled screen 

Inserting a File Into a File 

:r filename 		 insert (read) filename after cursor 

:34 r filename 		 insert filename after line 34 

Saving and Quitting 

:w 		 save changes (write buffer) 

:w filename 		 write buffer to filename

:wq 		 save changes and quit vi 

ZZ 		 save changes and quit vi 

:q! 		 quit without saving changes

Author Profile

sysdba ;

Other posts by sysdba

Author's web site



Are you satisfied with this blog?
Why not subscribe our RSS Feed? you will always get the latest post.


Hi, Be the first leave some reply

Leave A Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>