All About Internet Mail
Software Summaries
All About Internet Mail Software Summaries

vi Editor

Introduction

vi is a text editor available on Unix hosts. Its main importance in this context is that vi is used as a message editor by several email packages, including Berkeley (BSD) Mail and Elm. In other words, when you indicate you want to create, forward, or reply to a message, your email program brings up vi for entering and editing text in the message.

In addition, vi can be useful for other important operations within Unix. It can be used to modify setting and parameter files (e.g., .pinerc, elmrc. .newsrc) for most Unix-based email and news packages. vi seems to be receiving renewed attention as a tool for creating and managing World-Wide Web pages on Unix hosts. One instructor remarked, "People who have avoided learning vi up till now, will learn it if that's what it takes to get on the Web."

vi is complicated, often unfriendly, and difficult for new users. Users who are less active in their dislike of this program are those who have become sufficiently familiar with it to be less frustrated with its features. vi survives in part because it is quite capable and partly because it has little competition. emacs, another Unix editor, is no less complicated or unfriendly. Pico (the message editor used with PINE) is a much friendlier Unix editor but is not always suitable for certain operations.

Command Summary

From the Unix prompt (%)

% vi

Start a new file.

% vi filename Open a file. If filename belongs to an existing file, vi will open that file. If filename is a new file, vi will open an empty file.

From within vi

vi has two operational modes; command and insert. Each has its unique functions and therefore you must be in the correct mode for each operation.

vi considers a word to be any group of characters (exclusive of punctuation) between spaces. A line is all the characters between carriage returns. Paragraphs are set off by a blank line.

Note: vi commands are case sensitive. Uppercase J joins two lines and lowercase j moves down one line.


Insert mode allows you to enter text from the keyboard. Any of the following commands will place you in insert mode. Text you type will force existing text to the right. Press <Esc> to stop inserting and return to command mode.

i
Insert text at cursor.
I
Insert text at the beginning of the current line.
a
Append text to the right of the cursor.

A
Append text to the end of the current line.
o
Open a new line after the current line.
O
Open a new line before the current line.


Command mode allows you to save the file, exit, search, move around the screen, delete text, and join lines. You start vi in command mode. You can return to command mode from insert mode by pressing .

Saving and Quitting

:r filename
Insert text from specified file at the cursor position.
:w
Save the current edited version of the file.
:w!
Save the file, overwriting earlier version.
:q
Quit file and exit vi. Will not work if there are unsaved changes.
:wq
Save the file and quit vi.
:q!
Quit file and exit vi, abandoning unsaved changes.

Moving Around the Screen

j
Move cursor down one line.
k
Move cursor up one line.
h
Move one character left.
l
Move one character right.
w
Move forward one word.
$
Move cursor to the end of the line.
^
Move to the beginning of the line.
0 (zero) also works.
{
Move to previous paragraph.
}
Move to next paragraph.
G
Go to the last line of the file.
xG
Go to line x.
With some systems, line and character cursor moves can be made with <arrow> keys. You can precede the above cursor commands with a number to multiply the action the indicated times. For example, 5j makes the cursor move down 5 lines.


Searching
/
text Search forward for the indicated text.
?
text Search backwards for the indicated text.
fx
Move to next occurrence of x.
Note: Searches are case sensitive. /pine will not locate PINE.


Deleting and Modifying Text
x
Delete character at cursor.
dw
Delete word: ie. characters from cursor to next space.
dd
Delete entire current line (i.e., all characters from previous carriage return to next carriage return.
D
Delete line from cursor forward.
r
Replace character at cursor. Next character you type will overwrite current character.
R
Replace characters from cursor forward. Everything you type will overwrite text as the cursor moves to the right, until you press <Esc> to stop.
J
Join next line to the current line.
u
Undo last change.


Cutting and Pasting
yy
Yank or copy current line in memory buffer.dd (delete current line) will also yank deleted text into buffer.
p
Add line previously "yanked" into memory after current line.
P
Add line previously "yanked" into memory before current line.


Source: All About Internet Mail . Berkeley : Library Solutions Press, 1997.
Copyright 1997 by Lee Jaffe
Do not reproduce without permission.