tags:

views:

1321

answers:

5

vim shows on every line ending ^M

How I do to replace this with a 'normal' linebreak?

A: 

^M is retrieved by ‘Control‘ + ‘v‘ and ‘m‘, so do

s/^M//g

Andrew Sledge
+7  A: 

On Linux and Mac OS, the following works

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

(where ^V means control-V and ^M means control-M)

Paul Tomblin
Why did this get a downvote? It works, even when your file is mashed onto one line because it's got the wrong line end.
Paul Tomblin
It really works and is exactly what you need when all your text is on one line.
Bart Schuller
Shouldn't %s/^V^M/^V^M/g be %s/^V^M//g ?
Adnan
No. My way replaces whatever is the line end in the file with the correct line end.
Paul Tomblin
The accepted answer is incorrect. this one works better.
luckytaxi
+9  A: 

Try this:

:%s/<Ctrl-V><Ctrl-M>//g

which means

:%s

substitute

<Ctrl-V><Ctrl-M>

^M characters (the Ctrl-V is a Vim way of writing the Ctrl ^ character)

//

with "" (NULL) characters (the character between the 2 forward-slash / characters)

g

And do it globally (not just the first occurrence on the line).

LeopardSkinPillBoxHat
this doesn't work! the one below this works!
luckytaxi
@luckytaxi - what does it do for you?
LeopardSkinPillBoxHat
it removed the ^M characters but doesn't insert the carriage return.
luckytaxi
+2  A: 

Look at the file type - DOS or Unix:

:set filetype=unix

The file will be written back without carriage return (CR, ^M) characters.

Jonathan Leffler
+2  A: 

Alternatively, there are open-source utilities called dos2unix and unix2dos available that do this very thing. On a linux system they are probably installed by default; for a windows system you can download them from http://www.bastet.com/ amongst others.

ConcernedOfTunbridgeWells