I often delete, yank, and paste using something like this:
:3,6y
Since Vim 7, I've switched to using relative line numbers. I find it's much easier to use relative line numbering with commands like h,j,k,l
etc.
Since switching to relative line numbering, I find it difficult to operate on absolute ranges (eg. :3,6y
). It takes me too long to determine what absolute line numbers I need to select since Vim is displaying relative line numbers.
What is the best/quickest way to use visual selection on a range if your setup is displaying relative line numbering? Naively, I'm looking for something like:
:-2,+8y
(yank the lines from 2 lines above my current position to
8 lines below my current position.)
To get into the Vim Visual Line mode, press “Shift+V” while you are in Vim's Normal mode.
The vi yy command "yanks" the current line into the vi general buffer. That is, it copies the line for you to put into the file immediately. The vi p and P commands "put" the line back into the file just after (p) or just before (P) the line on which the cursor is resting.
Did you try your naive thing?
:-2,+8y
is equivalent to :.-2,.+8y
and should do what you want.
Note that if you don't specify a number, 1
is assumed, so: :,+y
means .,.+1 y
: yank current and next line.
On :help range
it is not well explained. The relevant parts are here:
Line numbers may be specified with: *:range* *E14* *{address}*
[...]
. the current line *:.*
[...]
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.
What the doc does not tell is that if the +
r -
is not preceded with anything, .
is assumed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With