guilin 桂林
guilin 桂林

Reputation: 17422

can I replace multiline like this in vim?

I want keep my js in this style. I want write a map in vim to do it faster.

from:

var a = x;
var b = y;
var c = z;

to:

var a = x
  , b = y
  , c = z
  ;

Upvotes: 3

Views: 4233

Answers (2)

sehe
sehe

Reputation: 392999

My solution in a case like this would be

  1. position cursor on first var (e.g. {)
  2. 1f;C-vjr,wC-vjexkJJ

For info, the Align script has the inverse operation:

var a = x, b = y, c = z;
  1. VLeadera,, result:

 

var a = x;
var b = y;
var c = z;

Upvotes: 0

balki
balki

Reputation: 27664

Use the following command.

%s/;\nvar /\r , /gc

Upvotes: 12

Related Questions