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.
Yep. This kind of stuff can also be done with vimscript, python, or ruby, but macros are short and terse and easy to write. Vim even allows you to record your keypresses and save them to a macro.
Yes usually. However ruby doesn't necessarily use single characters (e.g. {/})to indicate the start/end of blocks, so vim doesn't know how to get to the beginning/end of a block.
N.B. When I say blocks I mean the standard understanding of blocks i.e. the code between two curly braces, not ruby blocks which are roughly equivalent to anonymous functions.
Comments
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 ;)
I couldn't even tell if your parody is a parody. Is that seriously the macro??
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.
Yep. This kind of stuff can also be done with vimscript, python, or ruby, but macros are short and terse and easy to write. Vim even allows you to record your keypresses and save them to a macro.
Yes usually. However ruby doesn't necessarily use single characters (e.g. {/})to indicate the start/end of blocks, so vim doesn't know how to get to the beginning/end of a block.
N.B. When I say blocks I mean the standard understanding of blocks i.e. the code between two curly braces, not ruby blocks which are roughly equivalent to anonymous functions.