Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I hide the eol doc chars ^M in VIM

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.

UPDATE

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.

like image 918
marekj Avatar asked Oct 01 '09 19:10

marekj


People also ask

How do I get rid of M in vim?

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.

Why is there m in vim?

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 .

How do I remove M from Windows?

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.

What does M mean in Unix?

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.


2 Answers

You may want to set fileformat to dos.

:ed ++ff=dos % 
like image 118
Michael Krelin - hacker Avatar answered Sep 30 '22 14:09

Michael Krelin - hacker


To hide them:

:set fileformats=dos 

To remove them (so you can later save the file as a unix file):

:%s/\r//g 
like image 33
jqno Avatar answered Sep 30 '22 14:09

jqno