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