Alex Rivera | Logout

Copy an entire function in Vim

Asked 2012-05-17T09:04:14.460
21

Is there a command to copy a complete function (not by selecting through mouse)?

For example, 10yy will copy 10 lines from the cursor position.

I do not know the number of lines of a function, but want to copy the entire function.

Is there any command to copy the entire function?

vim
Edit
Report

1 Answer

57

This is what I do in JavaScript and PHP:

va{Vy
  1. Place the cursor somewhere in my method,
  2. va{ to visually select the the code block,
  3. V to turn the selection from character-wise to line-wise,
  4. y to yank

If you are too deep and va{ only selects a portion of your function you can do more a{ until you select what you want.

answered 2012-05-17T11:40:09.333

Your Answer