- 论坛徽章:
- 0
|
Copy all lines and place them at the end of the file (making a
consecutive duplicate).
In addition to an absolute line address, you can specify an address
relative to the current line. The symbols + and -work like
arithmetic operators. When placed before a number, these symbols
add or subtract the value that follows. For example:
:.,.+20d
Delete from current line through the next 20 lines.
:226,$m.-2
Move lines 226 through the end of the file to two lines above
the current line.
:.,+20#
Display line numbers from the current line to 20 lines further
on in the file.
In fact, you don't need to type the dot (.) when you use + or -,
because the current line is the assumed starting position.
Without a number following them, + and -are equivalent to +1 and
-1, respectively.[2] Similarly, ++ and --each extend the range by an
additional line, and so on. The + and - can also be used with search
patterns, as shown in the next section.
[2] In a relative address, you shouldn't separate the plus or minus symbol from the number that follows it.
For example, +10 means "10 lines following," but +10 means "11 lines following (1+10)," which is probably
not what you mean (or want).
The number 0 stands for the top of the file (imaginary line 0). 0 is
equivalent to 1-, and both allow you to move or copy lines to the
very start of a file, before the first line of existing text. For example:
:-,+t0
Copy three lines (the line above the cursor through the line
below the cursor) and put them at the top of the file.
5.2.4 Search Patterns
Another way that ex can address lines is by using search patterns.
For example: |
|