replace ^M by command "join line"

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

replace ^M by command "join line"

Ulrich Leopold
Dear all,

I would like to replace the ^M carriage return by the command shift+j.
Something like:

:%s/^M$/shift+j/g

How can I do that? I just do not knwo how to specify shift+j in ed mode.

Cheers, Ulrich

Reply | Threaded
Open this post in threaded view
|

Re: replace ^M by command "join line"

Dominic Evans
Well I know how to do it in two steps :)

:g/^M/normal J
:%s/^M

Which will perform shift J on all lines containing ^M and then delete
all occurrences of ^M in the file.

Someone can probably improve this by making it a one liner for you.

Cheers,
Dom

On 19/09/05, Ulrich Leopold <[hidden email]> wrote:

> Dear all,
>
> I would like to replace the ^M carriage return by the command shift+j.
> Something like:
>
> :%s/^M$/shift+j/g
>
> How can I do that? I just do not knwo how to specify shift+j in ed mode.
>
> Cheers, Ulrich
>
>
Reply | Threaded
Open this post in threaded view
|

Re: replace ^M by command "join line"

Tim Chase-2
In reply to this post by Ulrich Leopold
> :%s/^M$/shift+j/g
>
> How can I do that? I just do not knwo how to specify shift+j in ed mode.

Sounds like you want to make your entire file into one line.  You
can do this with

        :%j

which will join all your lines (or for whatever other range you
specify instead of "%" for the whole file).  It does jockey your
spacing to normalize it, as shift+j does.  If you want to keep
your spaces too, you can use

        :%j!

If you want to do a substitution, you can do

        :%s/\n

which will replace all newlines with nothing.  If you want
semi-similar behavior to the above ":join" command, you can use

        :%s/\n\s*/ /

which will normalize your whitespace to a single space.

And just because it's Vim and there are a bajillion ways to do
just about anything :)

        ggVGJ

should also do the trick for you.

-tim







Reply | Threaded
Open this post in threaded view
|

Re: replace ^M by command "join line"

Dominic Evans
Well I know how to do it in two steps :)

:g/^M/normal J
:%s/^M

Which will perform shift J on all lines containing ^M and then delete
all occurrences of ^M in the file.

Someone can probably improve this by making it a one liner for you.

Cheers,
Dom

On 19/09/05, Tim Chase <[hidden email]> wrote:

> > :%s/^M$/shift+j/g
> >
> > How can I do that? I just do not knwo how to specify shift+j in ed mode.
>
> Sounds like you want to make your entire file into one line.  You
> can do this with
>
>         :%j
>
> which will join all your lines (or for whatever other range you
> specify instead of "%" for the whole file).  It does jockey your
> spacing to normalize it, as shift+j does.  If you want to keep
> your spaces too, you can use
>
>         :%j!
>
> If you want to do a substitution, you can do
>
>         :%s/\n
>
> which will replace all newlines with nothing.  If you want
> semi-similar behavior to the above ":join" command, you can use
>
>         :%s/\n\s*/ /
>
> which will normalize your whitespace to a single space.
>
> And just because it's Vim and there are a bajillion ways to do
> just about anything :)
>
>         ggVGJ
>
> should also do the trick for you.
>
> -tim
>
>
>
>
>
>
>
>
Reply | Threaded
Open this post in threaded view
|

Re: replace ^M by command "join line"

Bart Vetters
In reply to this post by Dominic Evans
Hi,

> Well I know how to do it in two steps :)
>
> :g/^M/normal J
> :%s/^M

:g /^M$/ s/^M// | norm J

... is one way to do it in one line, but is basically doing the same thing
you're doing in a less easy to comprehend way, so I think your way is better.

CU

Bart

Reply | Threaded
Open this post in threaded view
|

Re: replace ^M by command "join line"

Tim Chase-2
If your 'ff' setting is showing actual ^M characters in your text
(as if you have ff=unix with a few stray ^M character) and you
want to get rid of them as well as join them with the next line
then you should be able to do something like

        :%s/\r\_s*/ /g

Sorry if I misunderstood your original thoughts...

-tim