VI Reference Sheet




Entering the editor:	vi  
			All "C" programs should end with the ".c" extension.
			All FORTRAN programs should end with the ".f" extension.
			All Pascal programs should end with the ".p" extension.

Leaving the editor:	ZZ
			This exits and saves your work.  Case matters. 
			See line editor commands to exit and not save.

Creating Text

        a 		Append at right of cursor.
        A 		Append at end of current line.
        i 		Insert at left of cursor.
        I 		Insert at beginning of current line.
        o 		Create text on newline after current line.
        O 		Create text on newline above current line.
        ESC  	 	EXIT INPUT OR APPEND MODE.

Positioning in the Window

        $ 		Last character on the current line.
        0 		First character on the current line.
        #-  		Move up # number lines.
        #+  		Move down # number lines.
        j 		Down arrow
        k 		Up arrow
        l 		Right arrow
        h 		Left arrow
        Arrow Keys 	The arrow keys work. 
                   	Do not hold them down or you'll be sorry.

Scrolling Text

        ctrl-f		Forward one window.
        ctrl-b		Backward one window.
        G		Go to last line of current file.
        #G		Go to the #th line of the current file.
        ctrl-g		Give the current line number and status.

Delete Commands

        x		Delete 1 character.
        #x		Delete # number of characters.
        dw		Delete 1 word.
        #dw		Delete # number of words.
        dd		Delete 1 line.
        #dd		Delete # number of lines.
        D		Delete from cursor to EOLN.

Replacing Text

        r		Replace 1 character.
        R		Replace only those characters typed over.
        C		Replace characters up to EOLN.
        ESC		EXIT REPLACE MODE.

Moving Text

        yw		Yank copy of current word into buffer.
        Y		Yank copy of current line into buffer.
        #Y		Yank copy of # number of lines into buffer.
        p		Place copy of buffer after cursor.  
			NOTE: All deleted text was placed in this same buffer.

Misc. vi Commands

        %		Match ('s or }'s.  
			Note:  Place cursor over a ( or { and the % command 
			will automatically take you to the matching ( or }.
        J		Join lines.
        ctrl-l		Refresh the screen
        u		UNDO LAST CHANGE!

Line Editor Style Commands 

        :q!		Quit the editor and discard all changes.
        :w  	Write out contents of editor to that filename.
        :set number	Number lines.
        :set nonumber	Un-number lines.
        :#		Go to line #.
        :/pattern	Search forward for pattern.
        :?pattern	Search backward for pattern.
        :/		Repeat last forward search.
        :?		Repeat last backward search.
        :#,#s/old/new/	Substitute old pattern for new pattern on 
			lines # thru #.

Substitute Examples

        :1,5s/wite/write/
			This changes the first occurrence of "wite" to "write" 
			on lines 1 thru 5.

        :1,5s/wite/write/g
			This changes every occurrence of "wite" to "write" on 
			lines 1 thru 5.  ( Global substitution ) 

        :1,$s/wite/write/gc
			This changes every occurrence of "wite" to "write" on 
			lines 1 thur EOF.  The "c" option gives the user a
			chance to confirm each change.  ( y or n )

        :10,15s/^/    /
			This changes Beginning of line into four spaces on lines 
			10 thur 15.  (i.e. indents those lines)  The "^" is a 
			special character that matches beginning of line. 

        :.,12s/$/ ;/
			This changes End of line into a space and a semi-colon 
			on the current line thur line 12.  The "$" is a special 
			character that matches End of line.  The "." is a 
			shorthand way say "current line".




Comments to: webmaster@dca.fee.unicamp.br
Revised: April 9, 1996
URL: http://www.dca.fee.unicamp.br/sysadmin/helpstuff/vi.html
Copyright © 1996 - DCA