I have the following Ruby code:
if some_cond && another
foo_bar
end
and I want to change it to:
foo_bar if some_cond && another
What are the most idiomatic ways to do that in Vim?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Assuming that the cursor is located at the
if-line prior torefactoring (not necessarily at the beginning of that line),
I would use the following sequence of Normal-mode commands:
or this chain of Ex commands:
Here the
if-line is first moved down one line by the:move +command.The
:movecommand cuts a given range of lines (the current line, ifnot specified) and pastes it below the line addressed by the argument.
The
+address is a shorthand for.+1referring to the next line(see
:help {address}).Second, the line containing the body of the conditional statement is
joined with the just moved
if-line. The:joincommand concatenatesa given range of lines into a single line. The
-range is a shortenedform of the
.-1address referring to the line just above the cursor(see
:help {address}).Third, the newly joined line is unindented by one
shiftwidthusingthe
:<command.Finally, the remaining
end-line, which can now be addressed as+,is removed by the
:deletecommand.