Ruby block conversion macros for Vim
Yet another simple macro for Vim I've become quite fond of. Have you ever written a single-line block like
myobj.each{|x| do whatever with x }
only to realize later that you actually wanted to do quite a bit more and you need to turn that into the following?
myobj.each do |x| do stuff and some more end
Or maybe you're refactoring some code and see that a multi-line block can be collapsed into a single line using method chaining?
The following animation shows the behavior I wanted: 
This script requires matchit and vim-ruby.
After adding the snippet (ruby-block-conv.txt) to .vimrc, the :B command will turn
foo{|x| f(x); g; bar(x)}
into
foo do |x| f(x) g bar(x) end
and contrariwise.
You can also turn do/end into {} by selecting the block in visual mode and using the <Leader>B (in my case ,B) mapping.
Referer
- 71 http://vimmate.rubyforge.org/html/files/README.html
- 31 http://www.artima.com/forums/flat.jsp?forum=123&thread=136633
- 19 http://www.artima.com/buzz/community.jsp?forum=123
- 14 http://ozmm.org
- 10 http://subtech.g.hatena.ne.jp/secondlife/20070109/1168321812
- 7 http://del.icio.us/rdenatale/vimruby
- 2 http://ozmm.org/2006/04
- 2 http://del.icio.us/heap
- 2 http://del.icio.us/rdenatale
- 2 http://ozmm.org/2006/04/26
Keyword(s):[blog] [ruby] [vim] [macro] [block]
References:[Ruby support for Vim]