Go to the previous, next section.

Line addressing

An address represents the number of a line in the buffer. ed maintains a current address which is typically supplied to commands as the default address when none is specified. When a file is first read, the current address is set to the last line of the file. In general, the current address is set to the last line affected by a command.

A line address is constructed from one of the bases in the list below, optionally followed by a numeric offset. The offset may include any combination of digits, operators (i.e., `+', `-' and `^') and whitespace. Addresses are read from left to right, and their values are computed relative to the current address.

One exception to the rule that addresses represent line numbers is the address `0' (zero). This means "before the first line," and is legal wherever it makes sense.

An address range is two addresses separated either by a comma or semicolon. The value of the first address in a range cannot exceed the value of the the second. If only one address is given in a range, then the second address is set to the given address. If an n-tuple of addresses is given where n > 2, then the corresponding range is determined by the last two addresses in the n-tuple. If only one address is expected, then the last address is used.

Each address in a comma-delimited range is interpreted relative to the current address. In a semicolon-delimited range, the first address is used to set the current address, and the second address is interpreted relative to the first.

The following address symbols are recognized.

.
The current line (address) in the buffer.

$
The last line in the buffer.

n
The nth, line in the buffer where n is a number in the range `0,$'.

-
^
The previous line. This is equivalent to `-1' and may be repeated with cumulative effect.

-n
^n
The nth previous line, where n is a non-negative number.

+
The next line. This is equivalent to `+1' and may be repeated with cumulative effect.

+n
whitespace n
The nth next line, where n is a non-negative number. Whitespace followed by a number n is interpreted as `+n'.

,
%
The first through last lines in the buffer. This is equivalent to the address range `1,$'.

;
The current through last lines in the buffer. This is equivalent to the address range `.,$'.

/re/
The next line containing the regular expression re. The search wraps to the beginning of the buffer and continues down to the current line, if necessary. `//' repeats the last search.

?re?
The previous line containing the regular expression re. The search wraps to the end of the buffer and continues up to the current line, if necessary. `??' repeats the last search.

'lc
The line previously marked by a `k' (mark) command, where lc is a lower case letter.

Go to the previous, next section.