BSD 1 development
[unix-history] / exrefm / exrefm4.n
CommitLineData
2fd0a8e1
BJ
1.if !\n(xx .so tmac.e
2.SH
3Command addressing
4.PP
5As previously mentioned,
6many commands accept address specifications before the command itself
7is given.
8These consist of a series of addressing primitives,
9described below,
10separated by `,' or `;'.
11Such address lists are evaluated left-to-right.
12When addresses are separated by `;' the current line `.'
13is set to the value of the previous addressing expression
14before the next address is interpreted.
15If more addresses are given than the command requires,
16then all but the last one or two are ignored.
17If the command takes two addresses, the first addressed line must
18precede the second in the buffer.
19Null address specifications are permitted in a list of addresses,
20the default in this case is the current line `.';
21thus `,$' is equivalent to `\fB.\fR,$'.
22It is an error to give a prefix address to a command which expects none.
23.PP
24A simple example of command addressing is the command `1,$print'
25which prints all the lines in the buffer,
26the first `1' to the last `$'.
27The command
28`/^Thesis/;/Example' will search forward to the first line beginning
29with the string
30`Thesis',
31set the current line to be this line,
32and then search forward from this line for the string `Example'.
33If such a line is found, it is printed.
34.SH
35Addressing primitives
36.PP
37.B "Current and last lines."
38The current line is refered to symbolically by `\fB.\fR',
39the last line by `$'.
40The default address for most commands is the current line,
41thus `\fB.\fR' is rarely used alone as an address.
42Most commands leave the current line as the last line which they affect.
43.PP
44.B "Line numbers."
45The lines in the editing buffer are numbered sequentially from 1;
46the last line in the buffer may be referred symbolically to as `$'.
47The most primitive form of addressing refers to lines by their
48line numbers in the file.
49Some commands also allow reference to a hypothetical line 0.
50These commands operate before the first line of the buffer.
51Thus `0\ read\ header' places a copy of the contents of the file
52.I header
53before the first buffer line.
54.PP
55.B "Relative addresses."
56Addresses may also be specified relative to the current buffer line.
57Thus `\-5' refers to the fifth line preceding the current line while
58`\+5' refers to the fifth line after it.
59Similarly a single `\-' addresses the line before the current line while
60`++' addresses the second following line.
61Note that the forms `\fB.\fR+2', `+2' and `++'
62are all equivalent;
63if the current line is line 100 they all address line 102.
64.PP
65.B "Context searching."
66One of the most convenient ways of addressing the lines in the buffer
67is via ``content addressing'' or ``context searching.''
68Here we pick out a pattern in the line we wish to refer to and
69specify that pattern after the search delimiter `/' to search forwards
70or `?' to search backwards.
71If we are simply looking for this pattern, then this is all we need
72to do; `/Thesis' will search forward in the file and then
73print the first line, if any, containing the string `Thesis'.
74If we wish to give a command to be executed at this line we must
75close off the search string with a matching delimiter.
76Thus the command `/Thesis/delete' will delete the next line
77containing the string `Thesis'.
78The pattern here may actually be a regular expression.
79This allows, e.g. searching for a string at the beginning or end
80of a line.
81It is possible to search again for the same pattern by giving a null
82regular expression; that is either a form such as `//', or a
83single `/' or `?' immediately followed by a newline character.
84Context searches normally wrap around past the end of the file
85if necessary to continue the search.\u\s-2\(dg\s0\d
86.FS
87\(dg It is also possible to use the previous scanning or substitute regular
88expression for the scan; the forms are `\e/' and `\e&/' to scan forwards,
89`\e?' and `\e&?' to scan backwards respectively.
90.FE
91.PP
92.B "Marks."
93The final way of specifying a line in the buffer is with a
94.I mark .
95The
96.I mark
97command may be used to give a line a mark,
98which is denoted by a single lower case letter.
99Thus
100`mark a'
101will mark the current line with tag
102.I a .
103This line may be subsequently referred to in addressing as `\(aa\fIa\fR'.
104.PP
105.B "Previous context mark."
106One mark is automatically set by the editor.
107This is the previous context mark, referred to in addressing expressions
108via `\(aa\(aa'.
109Before each non-relative motion of the current line `\fB.\fR',
110the previous current line is marked with this special tag.\u\s-2\(dd\s0\d
111.FS
112\(dd This makes it easy to refer or return to this previous context.
113Thus if you specify a context search which leads you to a line other
114than you intended, you may return to the previous current line via
115`\(aa\(aa'.
116.FE
117.bp