How to replace in vim a newline by a space? - Editors

This is a discussion on How to replace in vim a newline by a space? - Editors ; Hello, how, i. e. with which command, can all newlines of a textfile be replaced by spaces with vim 6.1? Thanks for all good hints. Thomas Wiedmann...

+ Reply to Thread
Results 1 to 7 of 7

How to replace in vim a newline by a space?

  1. Default How to replace in vim a newline by a space?

    Hello,

    how, i. e. with which command, can all newlines of a textfile be replaced by
    spaces with vim 6.1?

    Thanks for all good hints.

    Thomas Wiedmann


  2. Default Re: How to replace in vim a newline by a space?

    On Jun 17, 3:43 am, "Thomas Wiedmann" <t...@gmx.de> wrote:
    > Hello,
    >
    > how, i. e. with which command, can all newlines of a textfile be replaced by
    > spaces with vim 6.1?
    >
    > Thanks for all good hints.
    >
    > Thomas Wiedmann


    Don't know 6.1 but in 7 it's:

    %s/\n/ /cg

    if you remove the 'c' it will just change them all without asking you
    to 'confirm' each one

    http://applications.linux.com/articl...d=13&pagenum=1

    rd


  3. Default Re: How to replace in vim a newline by a space?

    And to replace spaces with newlines you use:

    :%s/ /\r/g

    Mark


  4. Default Re: How to replace in vim a newline by a space?

    Sun, 17 Jun 2007 10:43:13 +0200 from Thomas Wiedmann <th.wm@gmx.de>:
    > how, i. e. with which command, can all newlines of a textfile be replaced by
    > spaces with vim 6.1?


    Replacing a newline with a space amounts to joining the lines.

    I believe :.,$J will do it.

    There's a mode setting to determine whether joined lines have a space
    between them. If you try the command and you don't get spaces, hit u,
    check the help for that mode and set it the other way. :-)

    --
    Stan Brown, Oak Road Systems, Tompkins County, New York, USA
    http://OakRoadSystems.com/

  5. Default Re: How to replace in vim a newline by a space?

    On Jun 17, 2:03 pm, "znxs...@gmail.com" <znxs...@gmail.com> wrote:
    > And to replace spaces with newlines you use:
    >
    > :%s/ /\r/g


    Why is newline \r and not \n in the replacement part of a vim regex?
    When matching it is \n and that's the "normal" designation. I've been
    wondering about that for ages.

    Tom


  6. Default Re: How to replace in vim a newline by a space?

    On 2007-06-18 03:08:46 -0500, bakert <bakert@gmail.com> said:

    > Why is newline \r and not \n in the replacement part of a vim regex?
    > When matching it is \n and that's the "normal" designation. I've been
    > wondering about that for ages.


    I think that this is the way that nedit does it, too.
    --
    Aaron Hsu <aaron.hsu@sacrificumdeo.net>

    "No one could make a greater mistake than he who did nothing because he
    could do only a little." - Edmund Burke


  7. Default Re: How to replace in vim a newline by a space?

    On 18 Jun, 09:08, bakert <bak...@gmail.com> wrote:
    > Why is newline \r and not \n in the replacement part of a vim regex?
    > When matching it is \n and that's the "normal" designation. I've been
    > wondering about that for ages.
    >
    > Tom


    I am not an authority on this but my understanding is that when you
    press the Enter key, that is in fact a carriage return (\r). However
    once inserted you get a line break (\n). Why this is done that way I
    am unaware.

    Hope that helps explain in some way why \r is used.

    Thanks
    Mark


+ Reply to Thread

Similar Threads

  1. Replies: 0
    Last Post: 11-12-2007, 08:15 PM
  2. Replies: 20
    Last Post: 11-02-2007, 04:15 AM
  3. String.Replace method not usable when knowing index to replace
    By Application Development in forum CSharp
    Replies: 10
    Last Post: 10-17-2007, 03:02 PM
  4. Replies: 2
    Last Post: 08-23-2007, 11:34 AM
  5. how to make replace function replace globally in a string
    By Application Development in forum Javascript
    Replies: 5
    Last Post: 07-03-2007, 03:02 PM