Skip to content


Replace ^M to new line in VIM

Line ending symbols is a never ending issue born a long time ago.
Unix (and Linux) uses a simple \n new line character while Windows and Mac OS X use \n\r (new line – carriage return) and \r (carriage return only) respectively.

If you open a non Unix file within the great text editor VIM, it probably shows up with a bunch of ^M characters at the end of every line (where ^ means CTRL). You can easily remove them with a common replace command as follows:

:%s/^V^M/\r/g

  • Share/Bookmark

Related posts:

  1. Regular expressions basics In computing, regular expressions, also referred to as regex or...
  2. Dynamic DNS with Linux using ddclient My router had a respectable lifetime but sometimes it is...
  3. Moving files from Windows to Linux rewriting name case Filename case doesn’t matter on Microsoft Windows and Apple Mac...

Related posts brought to you by Yet Another Related Posts Plugin.

Posted in Linux. Tagged with , .

4 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.

  1. jjj said

    This is help me a lot

    Thx again

  2. Andrew said

    Yes that \n \r in OS X I keep forgetting
    Thanks

Continuing the Discussion

  1. Replace ^M to new line in VIM | The Black Ball linked to this post on January 5, 2009

    [...] more here:  Replace ^M to new line in VIM Share and [...]

  2. Drab as a fool, aloof as a bard linked to this post on September 28, 2009

    Whitespace standards…

    When writing code, it is good to be consistent about how you use whitespace. When collaborating with others, it can actually be detrimental to your group’s productivity if there is a mix of systems, so the sensible thing is to pick a standard ea…

Some HTML is OK

(required)

(required, but never shared)

or, reply to this post via trackback.