.\" This module is believed to contain source code proprietary to AT&T.
.\" Use and redistribution is subject to the Berkeley Software License
.\" Agreement and your Software Agreement with AT&T (Western Electric).
.\" @(#)ae6 8.1 (Berkeley) 6/8/93
CUT AND PASTE WITH THE EDITOR
Now we move on to manipulating pieces of files _
individual lines or groups of lines.
This is another area where new users seem
The first step is to ensure that you know the
commands for reading and writing files.
Of course you can't go very far without knowing
Equally useful, but less well known, is the `edit' command
says `I want to edit a new file called
without leaving the editor.'
command discards whatever you're currently working on
It's exactly the same as if you had quit with the
except that if you have a pattern remembered, then a command
remembers the name of the file,
commands that don't contain a filename
will refer to this remembered file.
e file2 (edit new file, without leaving editor)
... (editing on file2) ...
(and so on) does a series of edits on various files
and without typing the name of any file more than once.
(As an aside, if you examine the sequence of commands here,
You can find out the remembered file name at any time
You can also change the name of the remembered file name with
which gets a copy of a precious file,
to guarantee that a careless
command won't clobber the original.
Inserting One File into Another
Suppose you have a file called
and you want the file called
to be inserted just after the reference to
somewhere is a line that says
and the data contained in
probably so it will be formatted
Table 1 shows that ... [response from ed]
The critical line is the last one.
here you asked for it to be read in right after
command without any address
Writing out Part of a File
The other side of the coin is writing out part of
the document you're editing.
you want to copy out into a separate file
that table from the previous example,
so it can be formatted and tested separately.
Suppose that in the file being edited
which is the way a table is set up for the
in a separate file called
first find the start of the table
(the `.TS' line), then write out the interesting part:
\&\*.TS [ed prints the line it found]
If you are confident, you can do it all at once with
/^\*e\*.TS/;/^\*e\*.TE/w table
and now you have two copies, one in the file you're still editing,
one in the file `table' you've just written.
write out a group of lines, instead of the whole file.
In fact, you can write out a single line if you like;
just give one line number instead of two.
For example, if you have just typed a horribly complicated line
and you know that it (or something like it) is going to be needed later,
then save it _ don't re-type it.
\&\*.\*.\*.more stuff\*.\*.\*.
\&\*.\*.\*.more stuff\*.\*.\*.
This last example is worth studying, to be sure you appreciate
move a paragraph from its present position in a paper
As a concrete example, suppose each paragraph in the paper
begins with the formatting command
Think about it and write down the details before reading on.
is to write the paragraph onto a temporary file,
delete it from its current position,
then read in the temporary file at the end.
Assuming that you are sitting on the
`.PP' command that begins
the paragraph, this is the sequence of commands:
That is, from where you are now
until one line before the next `\*.PP'
Then delete the same lines.
As we said, that's the brute force way.
it lets you do the whole set of operations
without any temporary file.
commands in that it takes up to two line numbers in front
that tell what lines are to be affected.
by a line number that tells where the lines are to go.
says to move all the lines between
etc., can be patterns between slashes,
signs, or other ways to specify lines.
Suppose again that you're sitting at the first line of the
As another example of a frequent operation,
you can reverse the order of two adjacent lines
Suppose that you are positioned at the first.
It says to move line dot to after one line after line dot.
If you are positioned on the second line,
command is more succinct and direct than
writing, deleting and re-reading.
When is brute force better anyway?
This is a matter of personal taste _
do what you have most confidence in.
The main difficulty with the
is that if you use patterns to specify both the lines
you are moving and the target,
you have to take care that you specify them properly,
or you may well not move the lines you thought you did.
command can be a ghastly mess.
Doing the job a step at a time
makes it easier for you to verify at each step
that you accomplished what you wanted to.
It's also a good idea to issue a
before doing anything complicated;
then if you goof, it's easy to back up
provides a facility for marking a line
with a particular name so you can later reference it
regardless of its actual line number.
This can be handy for moving lines,
and for keeping track of them even after they've been moved.
marks the current line with the name `x'.
If a line number precedes the
(The mark name must be a single lower case letter.)
Now you can refer to the marked line with the address
Marks are most useful for moving things around.
Find the first line of the block to be moved, and mark it
Then find the last line and mark it with
Now position yourself at the place where the stuff is to go
Bear in mind that only one line can have a particular
mark name associated with it
We mentioned earlier the idea of saving a line
that was hard to type or used often,
so as to cut down on typing time.
Of course this could be more than one line;
then the saving is presumably even greater.
provides another command,
for making a copy of a group of one or more lines
This is often easier than writing and reading.
command is identical to the
command, except that instead of moving lines
it simply duplicates them at the place you named.
duplicates the entire contents that you are editing.
is for creating a series of lines that differ only slightly.
\&.......... x ......... (long line)
Sometimes it is convenient to be able
to temporarily escape from the editor to do
perhaps one of the file copy or move commands
without leaving the editor.
provides a way to do this.
your current editing state is suspended,
command you asked for is executed.
When the command finishes,
will signal you by printing another
at that point you can resume editing.
command, including another
(This is quite common, in fact.)
In this case, you can even do another
systems, there is an additional (and preferable) mechanism called
which lets you suspend your edit session (or, for that matter,
any program), return to the shell from
which you invoked that program, and issue any commands, then resume
the program from the point where it was stopped. See
An Introduction to the C Shell