1

Let say I have a minified javascript function like this:

function(){for(a=0;++a>0;){console.log(a);}}

and I want to apply an agressive split on it, that is insert a new line for some characters. So I would have

function(
)
{
for(
a=0;
++a>0;
)
{
console.log(
a
)
;
}
}

Of course I can use multiple substitute like :

:s/{/{\r/g
:s/}/\r}/g
:s/(/(\r/g
:s/)/\r)/g
...

But.

Is there a way to use one (or two) substitute(s) to do the whole job?

  • Didn't try non-alphabet? \W – SibiCoder Jun 28 '16 at 13:19
  • You can specify what particular characters you wanted to put. It seemd that your statements contains =,.,+ as well – SibiCoder Jun 29 '16 at 6:02
4

yes, like this:

%s/[}{();]/&\r/g

Just noticed that, the output of above leave a:

a)

If it does matter, you can do a:

%s/.\zs)/\r)/g

to fix it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.