简体   繁体   中英

How to yank relative line?

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 (ie 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM