April 24, 2026

Remove Microsoft’s carriage-return character ^M

From Stackoverflow:

The ^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.

If you have a file with ^M at the end of some lines and you want to get rid of them, use this in Vim:

:%s/^M$//g

Press Ctrl+V Ctrl+M to insert that ^M.


personal computing command-line interface (cli) gnu linux trisquel shell literacy wiki data vim

No affiliate links, no analytics, no tracking, no cookies. This work © 2016-2025 by yctct is licensed under CC BY-SA 4.0 .   about me   contact me   all entries & tags   FAQ   GPG public key

GPG fingerprint: 2E0F FB60 7FEF 11D0 FB45 4DDC E979 E52A 7036 7A88