Saucier
Saucier

Reputation: 4360

Shift parts of multiple lines to new lines in vim simultaneously

I have a block of code, e.g.

    ...
    elseif a:flag ==# "replace" return "fg"
    elseif a:flag ==# "visual"  return "#b58900"
    elseif a:flag ==# "insert"  return "#268bd2"
    elseif a:flag ==# "normal"  return "#859900"
    elseif a:flag ==# "replace" return "#dc322f"
    elseif a:flag ==# "visual"  return 3
    elseif a:flag ==# "insert"  return 4
    elseif a:flag ==# "normal"  return 2
    elseif a:flag ==# "replace" return 1
    ...

Now I want to move the returnpart below the ìf statements of all lines at once. Is this possible in vim? I tried <C-v>I<CR><ESC>. But that does only move the first returnto a new line.

Upvotes: 1

Views: 99

Answers (1)

Paul Pepper
Paul Pepper

Reputation: 727

In command mode:

:%s/return/\r\t\treturn/gc

Omit the trailing gc to avoid the confirmation.

Upvotes: 2

Related Questions