Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does one yank a function call in vim?

Tags:

vim

editing

Suppose a line of text reads:

$x = ( frobnicate( foo( bar( $x, $y )[ 1 ]))[ 1 ]);

The cursor is on the 'f' of 'frobnicate' and I want to yank the text which includes the call to frobnicate. (That is, everything up to the 3rd closing parenthesis. I can certainly do:

y3f)

or do it interactively with

vf);;y

but neither of these is appealing. (I don't want to have to count the '3' manually, nor do the repeated find until I hit the end point.) Is there an easy way to accomplish the move from 'f' to the matching closing paren? I'm thinking something like the v_i 'inner word' motion command.

like image 578
William Pursell Avatar asked Dec 21 '10 13:12

William Pursell


People also ask

How to yank a line in vim?

To yank one line, position the cursor anywhere on the line and type yy . Now move the cursor to the line above where you want the yanked line to be put (copied), and type p . A copy of the yanked line will appear in a new line below the cursor.

How do I yank a block in vim?

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).

How do I delete a function in Vim?

If your cursor is on the line with the function name, try d } . It will delete everything to the next block (i.e. your function body). Within the function body itself, d a p will delete the 'paragraph'. You can delete a curly brace block with d a } .


1 Answers

y% seems to work.

From help %:

Find the next item in this line after or under the cursor and jump to its match. inclusive motion. Items can be: ([{}]) parenthesis or (curly/square) brackets

like image 120
heijp06 Avatar answered Oct 05 '22 14:10

heijp06