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?

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

1 Answer 1

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 and acknowledge you have read our privacy policy.

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