1

I have the following function:

[Test]
public void Some_Unit_Test_Function()
{
   // some setup-test-assert code
   ...
   // end of code
}

What's the 'vim' way of copying the entire function (including the [Test] attribute), and pasting it below the original function with one line spacing in-between. I want to end up with the following:

[Test]
public void Some_Unit_Test_Function()
{
   // some setup-test-assert code
   ...
   // end of code
}

[Test]
public void Some_Unit_Test_Function()
{
   // some setup-test-assert code
   ...
   // end of code
}

1 Answer 1

2

yapGo<C-o>p:

  1. yap to copy the paragraph
  2. G go to the end of file
  3. o to insert a new line and enter insert mode
  4. <C-o> to enter another command, more about this here
  5. and p to paste

Updated

  • Thank you for your comment @DBenKnoble, this answer now reflects entering insert mode
  • @Eternal21 step 3 shows a way to enter the new line

Hope this helps. Thank you for the feedback.

2
  • 2
    With yapG you arent in insert mode, so just follow with p. And in insert mode, <C-r>" works as well
    – D. Ben Knoble
    Jun 30, 2018 at 1:14
  • 1
    I accepted your answer as solution. One question though, after I press 'G' I end up on the closing bracket of the first function, so when I paste the new function I end up with no empty line between the two functions. What's the fastest way to get that line in there? For now I end up doing this: yapGo<Esc>p
    – Eternal21
    Jun 30, 2018 at 19:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.