1BSD/exrefm/exrefm4.n

.if !\n(xx .so tmac.e
.SH
Command addressing
.PP
As previously mentioned,
many commands accept address specifications before the command itself
is given.
These consist of a series of addressing primitives,
described below,
separated by `,' or `;'.
Such address lists are evaluated left-to-right.
When addresses are separated by `;' the current line `.'
is set to the value of the previous addressing expression
before the next address is interpreted.
If more addresses are given than the command requires,
then all but the last one or two are ignored.
If the command takes two addresses, the first addressed line must
precede the second in the buffer.
Null address specifications are permitted in a list of addresses,
the default in this case is the current line `.';
thus `,$' is equivalent to `\fB.\fR,$'.
It is an error to give a prefix address to a command which expects none.
.PP
A simple example of command addressing is the command `1,$print'
which prints all the lines in the buffer,
the first `1' to the last `$'.
The command
`/^Thesis/;/Example' will search forward to the first line beginning
with the string
`Thesis',
set the current line to be this line,
and then search forward from this line for the string `Example'.
If such a line is found, it is printed.
.SH
Addressing primitives
.PP
.B "Current and last lines."
The current line is refered to symbolically by `\fB.\fR',
the last line by `$'.
The default address for most commands is the current line,
thus `\fB.\fR' is rarely used alone as an address.
Most commands leave the current line as the last line which they affect.
.PP
.B "Line numbers."
The lines in the editing buffer are numbered sequentially from 1;
the last line in the buffer may be referred symbolically to as `$'.
The most primitive form of addressing refers to lines by their
line numbers in the file.
Some commands also allow reference to a hypothetical line 0.
These commands operate before the first line of the buffer.
Thus `0\ read\ header' places a copy of the contents of the file
.I header
before the first buffer line.
.PP
.B "Relative addresses."
Addresses may also be specified relative to the current buffer line.
Thus `\-5' refers to the fifth line preceding the current line while
`\+5' refers to the fifth line after it.
Similarly a single `\-' addresses the line before the current line while
`++' addresses the second following line.
Note that the forms `\fB.\fR+2', `+2' and `++'
are all equivalent;
if the current line is line 100 they all address line 102.
.PP
.B "Context searching."
One of the most convenient ways of addressing the lines in the buffer
is via ``content addressing'' or ``context searching.''
Here we pick out a pattern in the line we wish to refer to and
specify that pattern after the search delimiter `/' to search forwards
or `?' to search backwards.
If we are simply looking for this pattern, then this is all we need
to do; `/Thesis' will search forward in the file and then
print the first line, if any, containing the string `Thesis'.
If we wish to give a command to be executed at this line we must
close off the search string with a matching delimiter.
Thus the command `/Thesis/delete' will delete the next line
containing the string `Thesis'.
The pattern here may actually be a regular expression.
This allows, e.g. searching for a string at the beginning or end
of a line.
It is possible to search again for the same pattern by giving a null
regular expression; that is either a form such as `//', or a
single `/' or `?' immediately followed by a newline character.
Context searches normally wrap around past the end of the file
if necessary to continue the search.\u\s-2\(dg\s0\d
.FS
\(dg It is also possible to use the previous scanning or substitute regular
expression for the scan; the forms are `\e/' and `\e&/' to scan forwards,
`\e?' and `\e&?' to scan backwards respectively.
.FE
.PP
.B "Marks."
The final way of specifying a line in the buffer is with a
.I mark .
The
.I mark
command may be used to give a line a mark,
which is denoted by a single lower case letter.
Thus
`mark a'
will mark the current line with tag
.I a .
This line may be subsequently referred to in addressing as `\(aa\fIa\fR'.
.PP
.B "Previous context mark."
One mark is automatically set by the editor.
This is the previous context mark, referred to in addressing expressions
via `\(aa\(aa'.
Before each non-relative motion of the current line `\fB.\fR',
the previous current line is marked with this special tag.\u\s-2\(dd\s0\d
.FS
\(dd This makes it easy to refer or return to this previous context.
Thus if you specify a context search which leads you to a line other
than you intended, you may return to the previous current line via
`\(aa\(aa'.
.FE
.bp