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?

regards,
Christian


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.

While i was writing this mail, it felt indeed like a good start for a vimgolf challenge, but that was not my intention. I was working on a PHP project (Drupal actually) and my cursor happened to be at the beginning of a function which I had to yank in it's entirety. So I simply wondered what the most efficient way to do this would be. Mainly just to learn more about Vim. I started using Vim 7 months ago, and seem to have grasped most basic commands (and text-objects etc), but i'm pretty sure that i can improve my vim usage by more trying to combine these basic commands and use them more efficiently. I often find myself activating visual mode and pressing jjjjjjj and the y, while in a lot of cases i could do it in more efficient ways i think (and know, after i made the selection). The difficulty of learning vim is often in finding (and learning to use and repeat) these more efficient ways.

Thanks!
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