Back to the Linux Page


vi -- The Programmer's Editor

vi is the classic line editor used by Unix programmers. It seems to have been created before the advent of cursor keys...see the table for moving the cursor.

Follow these fast links:

Starting the Program
Function Command
Edit file vi filename

Back to Top

Writing Text & Exiting
Function Command
Write to current file :w
Write to new file :w filename
Write over existing file :w! filename
Write and Quit :wq
Quit (nothing changed) :q
Quit (ignoring changes) :q!

Back to Top

Moving the Cursor
Function Command
Right one character RightArrow or l or SPACE
Right to end of word e
Right to end of line $
Right to beginning of word w
Left one character LeftArrow or h
Left to beginning of word b
Left to beginning of line 0
Left to start of next line ENTER
Up one line UpArrow or k or -
Down one line DownArrow or j or +
Beginning of first line H
Beginning of Middle line M
Beginning of Last line L
To next sentence )
To previous sentence (
To next paragraph }
To previous paragraph {
Forward one screen ^F
Forward (Down) ½ screen ^D
Backward one screen ^B
Backward (Up) ½ screen ^U
Scroll window down one line ^E
Scroll window up one line ^Y
Search forward for pattern /pattern
Search backward for pattern ?pattern
Next occurrence forward n
Next occurrence backward N
N.B. ^ stands for the CTRL key. You do NOT need to learn all of these commands. Since the cursor keys work and you are not editing at 200 BAUD over a busy modem, running the cursor by holding down a cursor key is reasonably efficient. However, ^F and ^B are still useful.

Back to Top

Inserting New Text
Function Command
Append after cursor a
Append at end of line A
Insert before cursor i
Insert at beginning of line I
Open new line above current O
Open new line below current o
N.B. All of these commands are terminated by tapping ESC.

Back to Top

Modifying Text
Function Command
*Change to end of word cw
*Change to end of line c$ or C
*Change to beginning of line c0
*Substitute for entire line S
*Substitute for current character s
*Replace multiple characters R
Replace current character r
Join current line to next J
N.B. Commands marked by splat (*) are terminated by tapping ESC.

Back to Top

Deleting Text
Function Command
Delete line(s) [n]dd
Delete to end of current word dw
Delete to end of current line d$ or D
Delete to beginning of current line d0
Delete current character x

Back to Top

Undoing Most Recent Change
Function Command
Undo previous command u
Undo changes to current line U

Back to Top

Copying Text
Function Command
Copy (yank) line(s) into buffer [n]Y or [n]yy
Copy (yank) word(s) into buffer [n]yw
Copy (yank) to end of line y$
Copy (yank) to beginning of line y0
Copy (yank) to buffer x "xy
Put buffer before/above cursor P
Put buffer after/below cursor p
Put from buffer x "xp

Back to Top

Moving Text
Steps Command
Step 1 Use a Delete command
Step 2 Move the cursor
Step 3 Use p or P

Back to Top

Set Editor Options
Function Command
Review all editor options :set all
Show command mode :set showmode
Hide command mode :set noshowmode
Change tab stop to 3 characters :set tabstop=3
Show line numbers :set number
Don't show line numbers :set nonumber


© DFStermole 1998