On Tue, Oct 24, 2006 at 10:29:43PM +1000, Mark Woodward wrote:
> Hi everyone,
>
> has anyone written a vim function to toggle/convert ruby block types?
> ie:
>
> { |x| puts x }
>
> toggled becomes:
>
> do |x|
> puts x
> end
>
> toggled becomes:
>
> { |x| puts x }
>
> again
>
>
> So if the cursor is within the {} or between the do/end hitting a mapped
> 'toggle key' will convert one to the other.
>
> If not any ideas what would be the best way to attack this? Thought I'd
> ask before I try to reinvent the wheel.
>
>
> --
> Mark
If you use the matchit plugin (:help matchit-install) then this may
be easier. If the cursor is inside the block (either the multi-line
do/end block or the one-line {/} block) then you can use the [% motion
to go to the start of the block. Then you can enter Visual mode (v or
V) and use % to get to the end of the block. I suggest doing this
manually, then letting your function/command/menu item take over, but
you could also do it inside your function with something like
:normal [%vg%
While testing this, I noticed a bug in the [% motion that is
triggered by languages (like ruby) that have escaped colons in their
matching patterns. If you want to use [% with ruby, first get the
latest matchit.vim from
http://www.vim.org/scripts/script.php?script_id=39 .
HTH --Benji Fisher