Creating Visual Script to replace spaces with Carriage Returns

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Creating Visual Script to replace spaces with Carriage Returns

Jeff Baumgartner
Hey Guys
I have been trying to figure out a way to put a mapping or script in
my vimrc to allow me to go into VISUAL mode and select a block of text
and automatically replace ,\s* with returns but I'm have a lot of
trouble with the carriage returns.  Does anyone have a solution for
this:

Before:
siga, sigb, sigc, sigd,
sige, sigf, sigg, sigh,

After:
siga,
sigb,
sigc,
sigd,
sige,
sigf,
sigg,
sigh,

Thanks,
Jeff
Reply | Threaded
Open this post in threaded view
|

Re: Creating Visual Script to replace spaces with Carriage Returns

Tim Chase-2
> Before:
> siga, sigb, sigc, sigd,
> sige, sigf, sigg, sigh,
>
> After:
> siga,
> sigb,
> sigc,
> sigd,
> sige,
> sigf,
> sigg,
> sigh,

The following seems to do the trick:

        vnoremap <f5> :s/,\_s*/,\r/g<cr>

All characters in that are typed literally (the \r, the <cr>, etc).

The trick is that the colon automatically puts the '<,'> range in
for you in visual mode.

If you care to dissect it, that's "a comma followed by any white
space (including linebreaking characters)" replaced by "a comma
followed by a newline"

Seems to do the trick for me.

-tim