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}

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

I know that. I try to make myself comfortable using all the motion 
commands, but often I still use those simple motion commands.

regards,
Christian
-- 
Wenn aus einem Raum mit 3 Leuten 5 rauskommen, dann müssen erst wieder
2 reingehen, damit der Raum leer ist.

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