When I open the file in vim
, I am seeing strange ^M
characters.
Unfortunately, the world‘s favorite search engine does not do well with special characters in queries, so I‘m asking here:
What is this ^M
character?
How could it have gotten there?
How do I get rid of it?
^M
is a carriage-return character. If you see this, you‘re probably looking at a file that originated in the DOS/Windows world, where an end-of-line is marked by a carriage return/newline pair, whereas in the Unix world, end-of-line is marked by a single newline.:e ++ff=dos
The :e ++ff=dos command tells Vim to read the file again, forcing dos file format. Vim will remove CRLF and LF-only line endings, leaving only the text of each line in the buffer.
then
:set ff=unix
and finally
:wq
What is `^M` and how do I get rid of it?
原文:https://www.cnblogs.com/rusking/p/10575794.html