

Vim plugin makes Ruby blocks into text objects - subelsky
http://vimcasts.org/blog/2010/12/a-text-object-for-ruby-blocks/

======
burgerbrain
Stuff like this can usually be handled with a quick macro in Vim.

For example, I use the macro `zEkzfggj%jzfG` (minus backticks) to fold
everything above and below the current { and it's corresponding C block.

And now that I see all of it typed out like that, I'm not sure myself if this
is an argument for Vim, or a parody of an argument for it ;)

~~~
jamesjyu
I couldn't even tell if your parody is a parody. Is that seriously the macro??

~~~
burgerbrain
It is indeed a macro in vim. The key to realizing what's going on is to
realize that when I made it I didn't sit down an type that out... well, not
really.

Rather I just pressed qf (which starts recording a macro to 'f'), then
preformed the sequence of commands that would need to be done to do what I
wanted. You do it step by step while watching what's actually going on, so
it's not as hard as it seems. Then from then on I can just press @f to do what
would normally take all of those keys.

broken down, this is how the macro works:

zE - clear other folds

k - up

zf - start creating a fold from here to...

gg - ...the top of the document

j - down

% - go to the matching bracket

j - down

zf - start creating a fold from here to...

G - ...the bottom of the document

I don't really remember why those ups and downs were needed, maybe they're
not. Just how I typed it out at the time.

------
austintaylor
An indentation-based text object solves the same problem in a language-
agnostic way. There are several implementations out there. I maintain one that
includes proper handling of languages without ending block delimiters (python,
haml, sass): <http://github.com/austintaylor/vim-indentobject>

------
aditya
Nifty, but this seems like plugin overkill.

I just use matchit (<http://www.vim.org/scripts/script.php?script_id=39>) and
then I can do v% to visually select everything to the end of a block.

~~~
nelstrom
Matchit.vim is great too, but you have to position your cursor on one of the
block delimiting keywords (e.g. class, module, def, if, do or end) to make
`v%` do what you want. The nice thing about text-objects is that the target
area where you can trigger them to achieve the desired effect is much larger.

~~~
subelsky
plus you get the ability to increase and decrease the block scope with ir / ar

------
lemming
One of the little things that I love most about IntelliJ is its expand/shrink
selection command. It's one of those things that you have no idea how useful
it will be until you get used to it, then you can't live without it.

------
wmwong
This made me smile. Such a nice Christmas gift. I just started getting into
vim and things that solve little nagging annoyances really help me stick with
it. Thank you!

------
kingsidharth
Anything like this for Python? Any plug-in or built in macro?

------
chrismealy
Anybody know an emacs equivalent?

