On 03/10/2011 09:23 PM, Christian Brabandt wrote:
Hi Jeroen!

On Do, 10 Mär 2011, Jeroen Budts wrote:

On 03/10/2011 10:57 AM, Christian Brabandt wrote:
On Thu, March 10, 2011 10:35 am, Jeroen Budts wrote:
I'm looking for the quickest method to yank an entire (php) function
when the cursor is somewhere in the first line of the function
definition like this (| = cursor):

fun|ction foobar() {
    if (true) {
      return "not false :)";
    }
}

One possible solution would be:
jvaBVy
But I'm wondering if there it is possible in a shorter way and maybe
without using visual mode.

f{y%
or even shorter:
$y%
(if the opening brace is always the last character on the line)

Is this for something like vimgolf?

Thanks for your suggestion Christian! However when I try this, it
does not entirely do what I was looking for (my bad for not
explaning it good enough).
I want to yank the entire method, so that includes the entire first
line (function foobar() {). Your suggestion also works if i change
it to first invoke visual mode and at the end press V to change it
to visual line-mode, but i was wondering if it is somehow possible
to do this in just a few keystrokes and possibly without using
visual mode.

Oh yes. I tried your first version and somehow I only got the body of
the function so I suggested something, that should have worked similar.

However, if your functions are separated by blank lines, you can use the
} motion to jump between paragraphs. That would make your keysequence to
0y}


That does the trick indeed! Unless there are blank lines in the function, because vim sees it as different 'paragraphs'. But I figured out that in that case you can provide a count to the } command like 0y2} when there are two blank lines in the function. For me this is not really a problem as I try to keep my functions short (20 lines or less), so the blank lines are easy to count. If not, I can always fall back to the previous command-combinations with visual mode.
Thanks again! I learned some cool new tricks today :)

Jeroen

--
website: http://budts.be/ - twitter: @teranex
___________________________________
Registered Linux User #482240 - GetFirefox.com - ubuntu.com

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

Reply via email to