Copy Mutliple Line in Vim Until Empty Line

I would like to yank some lines beginning from 'some_code_to_copy' until the empty line and then do the same for 'some_other_cody_to_copy' in vim.

some_code_to_copy(){
   statement;
   statement;
   statement;
   statement;
}

some_other_code_to_copy(){
   other_statement;
   other_statement;
}

I could first count the lines of each function and then do 6yy for the first one and 4yy for the second one.

I could also use v to select the first function and then y to yank it. and repeat this for each function.

What I actually want is to navigate to the first line and then tell vim copy all lines until the empty line.

How can I do this?

1 Answer

You can do this with yip (which means "yank inner paragraph"). ip is a motion just like hjkl and $, ^, etc., so you can also use it for other things like dip do delete the paragraph, cip to change it, gcip to comment it out if you have the vim-commentator plugin, etc.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Robert Thorne

Robert Thorne

Automotive & Future Transportation Editor

Robert Thorne covers electric vehicle innovations, autonomous driving systems, global mobility trends, and automotive engineering developments.

Share this article
Twitter Facebook Pinterest