I assume that in your multi-line example, the output will look like this:
foo.each do |f| f.bars.each do |b| b.whatever end hash = { a: 123, b: 456 } end
that is, you should also replace f.bars.each{...} .
if this is the goal, try the following:
gg/each\s*{<enter>qqf{%send<esc><co>sdo<esc> nq200@q
brief explanation:
gg " move cursor to top /each\s*{<enter> " search pattern we want qq " start recording macro to register q f{ " move to { %send<esc> " move to closing {, and change it to "end", back to normal <co>sdo " back to beginning { and change it into "do" <esc>nq " back to normal, and go to next match, stop recording
then you can do, for example, 200@q and check the result.
source share