Is there a command to copy a complete function? (Not by selecting through mouse)
ex: 10yy
--> will copy 10
lines from the cursor position.
I do not know the no of lines of a function, but want to copy the entire function.
Is there any command to copy the entire function?
V]m : start visually selecting (line-wise) and then move your cursor to the opening bracket of the function body. %y : move your cursor to the closing bracket of the function body, then yank.
You can use a movement command or up, down, right, and left arrow keys. Press y to copy, or d to cut the selection. Move the cursor to the location where you want to paste the contents. Press P to paste the contents before the cursor, or p to paste it after the cursor.
You can copy a block of text by pressing Ctrl-v (or Ctrl-q if you use Ctrl-v for paste), then moving the cursor to select, and pressing y to yank. Now you can move elsewhere and press p to paste the text after the cursor (or P to paste before).
For copy: Place cursor on starting of block and press md and then goto end of block and press y'd. This will select the block to paste it press p. For cut: Place cursor on starting of block and press ma and then goto end of block and press d'a. This will select the block to paste it press p.
This is what I do in JavaScript and PHP:
va{Vy
va{
to visually select the the code block,V
to turn the selection from character-wise to line-wise,y
to yankIf you are too deep and va{
only selects a portion of your function you can do more a{
until you select what you want.
If you are using VIM, and function body in the programming language you happen to be enclosed with braces, you can just place the cursor on one of the braces and type y%
.
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