On 03/11/2011 05:06 AM, KF wrote:
On Mar 10, 5:35 pm, Jeroen Budts<[email protected]> wrote:
Hi,
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.
Another solution I found is:
v][Vy
But this only seems to work if the function itself is not indented and
when i tried it without visual mode (^y][) it didn't include the last
line (}).
You can redefine the ][ meaning: [ :help section ]
:map ][ /}<CR>b99]}
and using your sequence, should work quite well:
v][Vy
It seems that only way to go is using visual mode...
I tried this mapping but it doesn't seem to work for me when i try this
in a PHP class (functions are indented by 4 spaces). It jumps always to
the last } in the file, which is the } to close the class definition.
But while I was looking up the help on ][ (:help ][) and read about ]]
as well and I noticed that this also only looks for the } on the first
column. However, I have been using the ]] command successfully in PHP
files to jump from function to function when functions are indented
(because they are part of a class).
So this made me realize that the ]] command was already remapped
somewhere. After searching a bit (with :verbose map ]]?) I discovered
that the ftplugin for php (/usr/share/vim/vim73/ftplugin/php.vim in my
case) remaps the ]] and [[ commands (line 69) to be 'php-aware'. Sadly
it does not remap the ][ and [] to be as intelligent as well.
So now I'm wondering, shouldn't the php ftplugin be modified to also
remap the ][ and [] commands so they have a more consistent and
to-be-expected behavior? And would it be possible to come create a
working mapping? I guess something like 'search back for the nearest
class/function/interface definition, calculate the indent of that line,
and search for the first } with the same indent' could work (but only if
the php code is correctly indented)?
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