Note that if vi in your system is actually vim, you won't
see the ^M characters displayed. Vim sees the \r\n line
endings and opens up the file in dos format, wherein it
silently preserves the dos line endings. It will show this
when it starts up as part of displaying the file name, line
and character counts:
"foo" [dos] 3L, 9C
To have vim strip the ^M characters for you, change the
file format to "unix" as follows:
:set ff=unix