/kb

personal knowledgebase

Remove Windows line endings in VIM

with 5 comments

The Windows line endings (^M) can be easily removed with most editors. In ViM it is very easy.

To remove all windows line endings (and replace with nothing), type the following:

:%s/^V^M//g

(note that the ^V will not display).

Sometimes it is necessary to add a line break as well:

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

Partly based on a Tech Recipes article.

Theoretically related posts

Written by hgrimelid

November 17th, 2008 at 11:14 am

Posted in Editors

Tagged with , , , ,

5 Responses to 'Remove Windows line endings in VIM'

Subscribe to comments with RSS or TrackBack to 'Remove Windows line endings in VIM'.

  1. :%s/\r//g

    Another way

    14 Jan 09 at 15:40

  2. Easier:

    :set fileformat=unix

    Tor

    31 Jan 09 at 03:47

  3. set fileformat didn’t work on windows.

    :%s/\r//g works perfectly on windows.

    Greg

    10 Feb 09 at 10:39

  4. If you’re running Linux, you can also install ‘tofrodos’ and run,

    $ fromdos filename.txt

    Serrano

    29 Jun 11 at 09:20

Leave a Reply