^M at the end of every line in Vim

carriage-return, linefeed, newline, vim

Solution

As a command, type

:%s/^M$//

(To get ^M, press ^V ^M, where ^ is CTRL on most keyboards)

Problem

When I am editing source files using Vim and other editors, sometimes I get these `^M` characters at the end of each line. I think that it has something to do with editing a file on Windows and then on Linux. How can I remove all of these automatically?

Original source

Related problems