.\" @(#)e4 6.1 (Berkeley) 5/22/86
Experiment with the substitute command.
substitute for some word on a line with several occurrences of that word.
the other side of the coin
on the other side of the coin
A substitute command changes only the first occurrence of the first string.
You can change all occurrences by adding a
Try other characters instead of slashes to delimit the two sets
command \- anything should work
(If you get funny results using any of the characters
read the section on ``Special Characters''.)
Context searching \- ``/ . . . /''
With the substitute command mastered, you can move on to
another highly important idea of
Suppose you have the original three line text in the buffer:
to come to the aid of their party.
Suppose you want to find the line that contains
Now with only three lines in the buffer, it's pretty easy
to keep track of what line the word
But if the buffer contained several hundred lines,
and you'd been making changes, deleting and rearranging lines,
and so on, you would no longer really know what this line
Context searching is simply a method of specifying the desired line,
regardless of what its number is,
by specifying some context on it.
The way to say ``search for a line
that contains this particular string of characters''
/\fIstring of characters we want to find\fP/
is a context search which
is sufficient to find the desired line \-
it will locate the next occurrence of
the characters between slashes (``their'').
It also sets dot to that line
and prints the line for verification:
to come to the aid of their party.
``Next occurrence'' means that
starts looking for the string at line
searches to the end of the buffer,
then continues at line 1 and searches to line dot.
(That is, the search ``wraps around'' from
It scans all the lines in the buffer until it either finds the desired line
or gets back to dot again.
If the given string of characters can't be found in any line,
Otherwise it prints the line it found.
You can do both the search for the desired line
substitution all at once, like this:
to come to the aid of the party.
There were three parts to that last command:
context search for the desired line, make the substitution, print the line.
is a context search expression.
all context search expressions are like this \-
a string of characters surrounded by slashes.
Context searches are interchangeable with line numbers,
so they can be used by themselves to find and print a desired line,
or as line numbers for some other command, like
They were used both ways in the examples above.
Suppose the buffer contains the three familiar lines
to come to the aid of their party.
are all context search expressions, and they all refer
to the same line (line 2).
To make a change in line 2,
The choice is dictated only by convenience.
You could print all three lines by, for instance
or by any number of similar combinations.
The first one of these might be better if you don't
know how many lines are involved.
(Of course, if there were only three lines in the buffer,
but not if there were several hundred.)
The basic rule is: a context search expression is
a line number, so it can be used wherever a line number is needed.
Experiment with context searching.
of the same string of characters, and scan through it using
Try using context searches as line numbers for the
substitute, print and delete commands.
Try context searching using
This scans lines in the buffer in reverse order
sometimes useful if you go too far while looking for some
string of characters \- it's an easy way to back up.
(If you get funny results with any of the characters
read the section on ``Special Characters''.)
provides a shorthand for repeating a context search
will find the next occurrence of
It often happens that this is not the desired line,
so the search must be repeated.
This can be done by typing merely
This shorthand stands for ``the most recently used
context search expression.''
also be used as the first string of the substitute
which will find the next occurrence of
This can save a lot of typing.
means ``scan backwards for the same expression.''