I have relative line numbers turned on.
I can yank line 10 using :10y
.
But how to I yank say the 5th line below the current line without jumping to said line, yanking and jumping back (i.e. 5jY5k
).
If I had this file:
2 describe 'foobar' do
1 it 'should be cool' do
46 # do stuff
1 end
2 end
I am on line 46 and I want to yank relative line 1 or 2, either above or below.
You can use +n
and -n
for relative addresses:
:+2y " Two lines after the current line
:-2y " Two lines before the current line
And you can also combine this:
:-2,+2y " Two lines before the cursor and two lines after
Also see this answer for some more examples and :help [range]
for the Vim documentation.
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