*cmdline-ranges* *[range]* *E16*
Some Ex commands accept a line range in front of them. This is noted as
[range]. It consists of one or more line specifiers, separated with ',' or
';'.
The basics are explained in section |10.3| of the user manual.
*:,* *:;*
When separated with ';' the cursor position will be set to that line
before interpreting the next line specifier. This doesn't happen for ','.
Examples: >
4,/this line/
< from line 4 till match with "this line" after the cursor line. >
5;/that line/
< from line 5 till match with "that line" after line 5.
The default line specifier for most commands is the cursor position, but the
commands ":write" and ":global" have the whole file (1,$) as default.
If more line specifiers are given than required for the command, the first
one(s) will be ignored.
Line numbers may be specified with: *:range* *{address}*
{number} an absolute line number *E1247*
. the current line *:.*
$ the last line in the file *:$*
% equal to 1,$ (the entire file) *:%*
't position of mark t (lowercase) *:'*
'T position of mark T (uppercase); when the mark is in
another file it cannot be used in a range
/{pattern}[/] the next line where {pattern} matches *:/*
also see |:range-pattern| below
?{pattern}[?] the previous line where {pattern} matches *:?*
also see |:range-pattern| below
\/ the next line where the previously used search
pattern matches
\? the previous line where the previously used search
pattern matches
\& the next line where the previously used substitute
pattern matches
*:range-offset*
Each may be followed (several times) by '+' or '-' and an optional number.
This number is added or subtracted from the preceding line number. If the
number is omitted, 1 is used. If there is nothing before the '+' or '-' then
the current line is used.
*:range-closed-fold*
When a line number after the comma is in a closed fold it is adjusted to the
last line of the fold, thus the whole fold is included.
When a number is added this is done after the adjustment to the last line of
the fold. This means these lines are additionally included in the range. For
example: >
:3,4+2print
On this text:
1 one ~
2 two ~
3 three ~
4 four FOLDED ~
5 five FOLDED ~
6 six ~
7 seven ~
8 eight ~
Where lines four and five are a closed fold, ends up printing lines 3 to 7.
The 7 comes from the "4" in the range, which is adjusted to the end of the
closed fold, which is 5, and then the offset 2 is added.
An example for subtracting (which isn't very useful): >
:2,4-1print
On this text:
1 one ~
2 two ~
3 three FOLDED ~
4 four FOLDED ~
5 five FOLDED ~
6 six FOLDED ~
7 seven ~
8 eight ~
Where lines three to six are a closed fold, ends up printing lines 2 to 6.
The 6 comes from the "4" in the range, which is adjusted to the end of the
closed fold, which is 6, and then 1 is subtracted, then this is still in the
closed fold and the last line of that fold is used, which is 6.
*:range-pattern*
The "/" and "?" after {pattern} are required to separate the pattern from
anything that follows.
The "/" and "?" may be preceded with another address. The search starts from
there. The difference from using ';' is that the cursor isn't moved.
Examples: >
/pat1//pat2/ Find line containing "pat2" after line containing
"pat1", without moving the cursor.
7;/pat2/ Find line containing "pat2", after line 7, leaving
the cursor in line 7.
The {number} must be between 0 and the number of lines in the file. When
using a 0 (zero) this is interpreted as a 1 by most commands. Commands that
use it as a count do use it as a zero (|:tag|, |:pop|, etc). Some commands
interpret the zero as "before the first line" (|:read|, search pattern, etc).
Examples: >
.+3 three lines below the cursor
/that/+1 the line below the next line containing "that"
.,$ from current line until end of file
0;/that the first line containing "that", also matches