Introduction to Vi: the UNIX Visual Display Editor

INTRODUCTION

Vi, or "vee eye," is the standard screen editor on UNIX and is integrated with ex, a line editor. Vi is the visual mode of ex, and ex commands can be entered while using vi, making it a very powerful editor.

Press the Return key after you type a command in on the system. Users are encouraged to consult the UNIX Help Desk, 12D Zachry, 847-UNIX, for further information or suggestions about this document or vi.

ENTERING VI

To invoke vi type

	vi filename

where "filename" is the name of an existing or new file.  If "filename" is an 
existing file, the screen will show its contents, ready for editing.  If 
"filename" does not already exist, the new file will initially appear on the 
screen with one tilde (~) on each line in the first column.  The tilde 
represents a blank line in any file and is used primarily to fill up the 
terminal screen after the last line of the file, if there is any existing 
text.  The last line on the screen is reserved for echoing certain commands 
as they are entered, or for showing informative messages given by vi.  Example 
("%" is a command prompt):

	% vi New_file  
	|
	~
	~
	~
	~
	~
	~
	~
	~
	~
	"New_file" [New file]

Once you are in the editor, enter the command i to input text.

A COPY OF YOUR FILE -- THE BUFFER

A copy of your file, or a buffer, is created when you edit a file using vi. This temporary workspace is where you will do your editing. The buffer is not saved until you do a write (:w, :wq, or -zz) command. This copies the buffer onto disk and replaces the previous version of the file if one existed, or creates a file if not.

TWO MODES IN VI

Editing in vi means alternating between the text input mode and the command 
mode. 

* The text input mode is where all characters that you type in are interpreted  
  as text and inserted into the buffer.  The ESC key (ESCAPE; F11 on vt200s) 
  allows you to exit the input mode and return to the command mode.  

* The command mode is where all characters that you type in are interpreted as  
  commands.	

* You are in the command mode when you first enter vi.        

* Most commands are used for moving around a file.

* A handful of commands enable you to enter the text input mode.

* ESC allows you to exit the input mode and return to the command mode.  

EXITING VI

* To write (save) the file and exit vi, enter ZZ, :wq, or :x. * To quit vi without saving the most recent changes, issue the command :q!.

VI ON-LINE TUTORIAL

There is an on-line tutorial for vi on all the TamUnix systems.  type 

     vi_practice 

to access it. 

BASIC VI COMMANDS

Here are some basic vi commands:  

Command		Comments

ESC (ESCAPE)	Ends text input and returns to command mode 
i           	Input text to left of cursor 
a            	Input text to right of cursor 
o            	Input text  below current line 
h             	Move to immediate left 
l or SPACE	Move to immediate right 
k   		Move up in same column 
j 		Move down in same column
Control-d        Scroll down half screen 
Control-u        Scroll up half screen 
Control-f        Scroll forward full screen 
Control-b        Scroll back full screen 
0     		Move to start of current line 
$     		Move to end of current line 
H		Move to start of current window 
L     		Move to end of current window 
nG    		Move to nth line of file 
G		Move to end of file 
/string		Move forward to first occurrence of string   
x		Delete current character 
dw		Delete current word 
dd		Delete current line 
r character  	Replace current character by character
R          	Replace characters one by one (overwrite) 
u      		Undo last deletion, input, or replacement