tags:

views:

166

answers:

3

In php, if I have a function such as:

function test($b) {

  var $a = 0;

  while ($a < b) {
    $a += 3;
  }

  return $a;
}

If the cursor is on the $a += 3 line, is it possible to quickly select the entire function? "v2aB" would select everything including the function braces but not the declaration "function test($b) "

+3  A: 

Press V after the selection command you post, to convert the selection to line selection, and it will select the function declaration:

v2aBV

CMS
Does this depend on some other mode? I tried it and all it does is flash (beep) after B.
wallyk
@wallyk: Will work on normal mode, after `B` is pressed (*make sure is capital **B***) the block selection will appear, and then when `V` is pressed, the selection will include the function declaration, since it's in the same line that the opening curly brace...
CMS
That's great, thanks. Is it possible to map this such that it doesn't depend on the nesting level?
CNelson
`v2aBV` is equivalent to `V2aB`.
Ewan Todd
@Ewan: Try it out, the `iB` part of the command will make that the initial line selection (started with `V`), become a normal character selection.
CMS
A: 

Here's a mapping that seems to work very well, no matter the nesting level.

:map t ? function <CR>f{vaBV
CNelson
A: 

Here's another method that will work if you have function-level folding turned on: z c v

That closes the current fold and selects it, but it leaves it closed. If you want it to remain open: z c v $

If you have block-level folding turned on, you would have to close twice, since you're inside the while loop, so: 2 z c v

To enable PHP class/function folding: let php_folding = 1

oops