I've got a post on how to replace ^M inline, but here's another option for VIm v7.2.40+, as detailed in vim.wikia.com:

To convert the current file from any mixture of CRLF/LF-only line endings, so all lines end with LF only:

:update Save any changes.

:e ++ff=dos Edit file again, using dos file format ('fileformats' is ignored).

:setlocal ff=unix This buffer will use LF-only line endings when written.

:w Write buffer using unix (LF-only) line endings.

To save to DOS format, just skip the :setlocal step.

I hadn't seen the ++ff=dos jive before, I don't think. That's interesting.

The "magic" comes from this, which I wouldn't've guessed:

When reading as dos, all CRLF line endings, and all LF-only line endings, are removed.

Labels: ,