In gvim
on windows if I have text with CRLF
eol
then the text will display ^M
at the end of each line.
How do I 'hide' that special char from display?
The :set nolist command """
does not dismiss it.
I did :set fileformats=unix,dos
as a list. It didn't work at first, but I closed the file and reopened it again and it worked.
By default I had set fileformats to only unix value.
Thanks for answers.
How can I remove ^M characters from text files? A. ^M are nothing more than carriage return, so it is easy to use the search and replace function of vim to remove them. That will do the job.
The character that vim displays as ^M is CR (carriage return, ASCII character 13). Windows uses both CR and LF (new line, ASCII character 10) to encode line breaks in text files. Linux/Unix use only LF to encode line breaks, and Mac OS uses only CR .
Search for \r (which is ^M) and replace with nothing (unless you want a newline, then replace with \n). Since you do not want all ^M's replaced, do not press replace all, choose the ones you want to replace. If you use regular windows notepad, the ^M's will show up as boxes.
Control M ( ^M) characters are introduced when you use lines of text from a windows computer to Linux or Unix machine. Most common reasons are when you directly copy a file from a windows system or submit form data copied and pasted from a windows machine.
You may want to set fileformat
to dos
.
:ed ++ff=dos %
To hide them:
:set fileformats=dos
To remove them (so you can later save the file as a unix file):
:%s/\r//g
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With