^M in the source code - grant-guo/Ideas GitHub Wiki

Vim does show ^M except in one case: if the fileformat=dos then it will not show a trailing crlf.

You can find out which format (unix or dos) you have by typing :set and you can get rid of the ^M in the crlf by just changing the format (:set fileformat=unix) and then writing out the file.

If you have a ^M in the middle of the line, then you should be able to see it, even in a fileformat=dos file, and you can pattern match it with \r. (Oddly, the syntax for subsituting a newline is a \r in the replacement part of the sub, so the way one changes ^M to ^N is by the not-at-all-a-noop :s/\r/\r/.)

here is link to refer to:

https://its.ucsc.edu/unix-timeshare/tutorials/clean-ctrl-m.html

content as following:

Remove CTRL-M characters from a file in UNIX

Description

How to remove CTRL-M characters from a file in UNIX.

You may need to do this when you import a text file from MS-DOS (or MS-Windows), and forget to transfer it in ASCII or text mode. Here are several ways to do it; pick the one you are most comfortable with.

The easiest way is probably to use the stream editor sed to remove the ^M characters. Type this command: % sed -e "s/^M//" filename > newfilename

To enter ^M, type CTRL-V, then CTRL-M. That is, hold down the CTRL key then press V and M in succession.

You can also do it in vi: % vi filename

Inside vi [in ESC mode] type: :%s/^M//g

To enter ^M, type CTRL-V, then CTRL-M. That is, hold down the CTRL key then press V and M in succession.

You can also do it inside Emacs. To do so, follow these steps:

Go to the beginning of the document

Type: M-x replace-string RET C-q C-m RET RET

where "RET" means and C-q and C-m mean <hold the CTRL key and press the m (or q) key>.