Does anyone have a plugin or macro to replace matching {
braces }
with do
and end
in Vim? Preferably turning a single-line statement like this:
foo.each { |f| f.whatever }
into:
foo.each do |f|
f.whatever
end
I could make a macro myself for that one case, but I'd like something that could also handle converting existing multi-line, potentially complicated blocks, like:
foo.each { |f|
f.bars.each { |b| b.whatever }
hash = { a: 123, b: 456 }
}
into:
foo.each do |f|
f.bars.each { |b| b.whatever }
hash = { a: 123, b: 456 }
end
I've looked at vim-surround and rails.vim, and haven't found a way with either.
There is a Vim plugin called Vim Blockle that performs this function.
Once you install the plugin you put the cursor on the {
}
do
or end
and press <Leader>b
to swap the block styles.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With