Replacing characters with newlines

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

Replacing characters with newlines

Giorgos Gaganis
Hello

I would like to split some lines at the occurence of some characters.
How can I do that in vim?

I have tried s/,/\n/g but it is no help.

For now I am getting out of vim and use the 'tr' command.


Thanks
Giorgos

Reply | Threaded
Open this post in threaded view
|

RE: Replacing characters with newlines

vishnu-3
Hi Giorgos,

Use \r instead of \n.

:%s/,/\r/g

~VIshnu

-----Original Message-----
From: Giorgos Gaganis [mailto:[hidden email]]
Sent: Monday, August 08, 2005 6:37 PM
To: [hidden email]
Subject: Replacing characters with newlines

Hello

I would like to split some lines at the occurence of some characters.
How can I do that in vim?

I have tried s/,/\n/g but it is no help.

For now I am getting out of vim and use the 'tr' command.


Thanks
Giorgos

kae
Reply | Threaded
Open this post in threaded view
|

Re: Replacing characters with newlines

kae
In reply to this post by Giorgos Gaganis
Giorgos Gaganis wrote:

> Hello
>
> I would like to split some lines at the occurence of some characters.
> How can I do that in vim?
>
> I have tried s/,/\n/g but it is no help.
>
> For now I am getting out of vim and use the 'tr' command.
>
>
> Thanks
> Giorgos
>

replace the \n with CTRL+V [enter]

it should look something like:
s/,/^M/g

Kae

Reply | Threaded
Open this post in threaded view
|

Re: Replacing characters with newlines

Tim Chase-2
In reply to this post by Giorgos Gaganis
> I have tried s/,/\n/g but it is no help.

sooooo close :)  Try

        s/,/\r/g

I can't explain it...I'd figure that "\n" would be
what one would want too, but I just smile & nod :)

There are other suggestions found under

        :help sub-replace-special

(you'll have to look down a bit to the line on "\r"
and its neighboring lines)

-tim