How to convert the ^M linebreak to 'normal' linebreak in a file opened in vim?

ByteNirvana picture ByteNirvana · May 1, 2009 · Viewed 380.4k times · Source

vim shows on every line ending ^M

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

Answer

LeopardSkinPillBoxHat picture LeopardSkinPillBoxHat · May 1, 2009

Command

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

Where <Ctrl-V><Ctrl-M> means type Ctrl+V then Ctrl+M.

Explanation

:%s

substitute, % = all lines

<Ctrl-V><Ctrl-M>

^M characters (the Ctrl-V is a Vim way of writing the Ctrl ^ character and Ctrl-M writes the M after the regular expression, resulting to ^M special character)

/\r/

with new line (\r)

g

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