Skip to content

Instantly share code, notes, and snippets.

@i0rek
Created Feb 22, 2012
Embed
What would you like to do?
Some search/replace stuff for vim to clean up rspecs in mongoid.
# let (:klass) { Person }
# to
# let(:klass) do
# Person
# end
:%s/\(\s*\)let(:\(.*\)) {\s*\(.*\)\s*}/\1let(:\2) do\r\1 \3\r\1end/g
# before { do_something }
# to
# before do
# do_something
# end
:%s/\(\s*\)\(before\|after\) { \(.*\) }/\1\2 do\r\1 \3\r\1end/g
# add newlines
:%s/end\_\s\(\s*let(\)/end\r\r\1/g
:%s/end\_\s\(\s*it\s\)/end\r\r\1/g
:%s/end\_\s\(\s*before\s\)/end\r\r\1/g
:%s/end\_\s\(\s*after\s\)/end\r\r\1/g
:%s/do\_\s\(\s*let(\)/do\r\r\1/g
:%s/do\_\s\(\s*it\s\)/do\r\r\1/g
:%s/do\_\s\(\s*context\s\)/do\r\r\1/g
# same as above, but as bufdo
:bufdo %s/\(\s*\)let(:\(.*\))\s*{\s*\(.*\)\s*}/\1let(:\2) do\r\1 \3\r\1end/ge | update
:bufdo %s/\(\s*\)\(before\|after\) { \(.*\) }/\1\2 do\r\1 \3\r\1end/ge | update
:bufdo %s/end\_\s\(\s*let(\)/end\r\r\1/ge | update
:bufdo %s/end\_\s\(\s*it\s\)/end\r\r\1/ge | update
:bufdo %s/end\_\s\(\s*before\s\)/end\r\r\1/ge | update
:bufdo %s/end\_\s\(\s*after\s\)/end\r\r\1/ge | update
:bufdo %s/do\_\s\(\s*let(\)/do\r\r\1/ge | update
:bufdo %s/do\_\s\(\s*it\s\)/do\r\r\1/ge | update
:bufdo %s/do\_\s\(\s*context\s\)/do\r\r\1/ge | update
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment