MiniUnix/usr/doc/ed/e1
.TL
A Tutorial Introduction to the \s-2UNIX\s+2 Text Editor
.sp
.AU
B. W. Kernighan
.sp
.AI
Bell Laboratories, Murray Hill, N. J.
.nr PS 9
.nr VS 11
.if t .2C
.H1
Introduction
.H2
.PG
.ul
Ed
is a ``text editor'', that is, an interactive program
for creating and modifying ``text'',
using directions provided by a user at
a terminal.
The text is often a document
like this one,
or a program
or perhaps data for a program.
.PG
This introduction is meant to simplify learning
.ul
ed.
The recommended way to learn
.ul
ed
is to read this document,
simultaneously using
.ul
ed
to follow the examples,
then to read the description in section I of the
.S1
UNIX
.S2
manual, all the while
experimenting with
.ul
ed.
(Solicitation of advice from experienced users is also useful.)
.PG
Do the exercises!
They cover material not completely discussed
in the actual text.
An appendix summarizes the commands.
.H1
Disclaimer
.H2
.PG
This is an introduction and a tutorial.
For this reason, no attempt is made to
cover more than a part of the facilities that
.ul
ed
offers
(although this fraction includes the most useful and frequently used
parts).
Also,
there is not enough space to explain basic
.S1
UNIX
.S2
procedures.
We will assume that you know how to log on to
.S1
UNIX,
.S2
and that you have at least a vague understanding
of what a file is.
.PG
You must also know what character to type as the end-of-line
on your particular terminal.
This is a ``newline'' on Model 37 Teletypes,
and ``return'' on most others.
Throughout, we will refer to this character,
whatever it is,
as ``newline''.
.H1
Getting Started
.H2
.PG
We'll assume that you have logged in to
.S1
UNIX
.S2
and it has just said ``%''.
The
easiest way to get
.ul
ed
is to type
.X1
ed (followed by a newline)
.X2
You are now ready to go \(mi
.ul
ed
is waiting for you to tell it what to do.
.H1
Creating Text \(mi the Append command ``a''
.H2
.PG
As our first problem, suppose we want to create some text
starting from scratch.
Perhaps we are typing the very first
draft of a paper; clearly it will have to start
somewhere, and undergo modifications later.
This section will show how to get some text in, just to
get started.
Later we'll talk about how to change it.
.PG
When
.ul
ed
is first started, it is rather like working
with a blank piece of paper \(mi there is no text
or information present.
This must be supplied by the person using
.ul
ed;
it is usually done
by typing in the text, or by reading it into
.ul
ed
from a
file.
We will start by typing in some text, and return shortly to how to
read files.
.PG
First a bit of terminology.
In
.ul
ed
jargon, the text being
worked on is said to be ``kept in a buffer.''
Think of the
buffer as a work space, if you like, or simply as the information
that you are going to be editing.
In effect the buffer is like the
piece of paper, on which we will write things, then change some
of them, and finally file the whole thing away for another day.
.PG
The user tells
.ul
ed
what to do to his text
by typing instructions called ``commands.''
Most
commands consist of a single letter,
which must be typed in lower case.
Each command is typed
on a separate line.
(Sometimes the command is preceded by information
about what line or lines of text are to be affected \(mi
we will discuss these shortly.)
.ul
Ed
makes no response
to most commands \(mi there is no prompting
or typing of messages like ``ready''.
(This silence is preferred
by experienced users, but sometimes a hangup for beginners.)
.PG
The first command is
.ul
append,
written as the letter
.X1
a
.X2
all
by itself.
It means ``append (or add) text lines to the buffer,
as I type them in.''
Appending is rather like
writing fresh material on a piece of paper.
.PG
So to enter lines of text into the buffer,
we just type an ``a'' followed by a
newline, followed by the lines of text we want, like this:
.X1
a
Now is the time
for all good men
to come to the aid of their party.
.li
\fB.\fR
.X2
.PG
The only way to stop appending is to type a
line that contains only a period.
The ``\*.'' is used
to tell
.ul
ed
that we have finished appending.
(Even experienced users forget that terminating ``\*.''
sometimes.
If
.ul
ed
seems to be ignoring you,
type an extra line with just ``\*.'' on it.
You may then find you've added some garbage lines
to your text, which you'll have to take out later.)
.PG
After the append command has been done, the buffer will
contain the three lines
.X1
Now is the time
for all good men
to come to the aid of their party.
.X2
The ``a'' and ``\*.'' aren't there, because they are
not text.
.PG
To add more text to what we already have,
just issue another ``a'' command, and continue typing.
.H1
Error Messages \(mi ``?''
.H2
.PG
If at any time you make an error in the commands you type to
.ul
ed,
it will tell you by typing
.X1
?
.X2
This is about as cryptic as it can be,
but with practice, you can usually
figure out how you goofed.