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

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


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


While convening on the DOS or Unix format once and for all is of course the preferable approach, sometimes some co-workers just don't care enough about proper source management to make their editors behave.

In those desperate cases, instead of converting the file completely (resulting in a file completely rewritten by yourself according to the SCM, rendering the “blame” function useless), I found it preferable to just pretend that the problem doesn't exist. If the compiler is accommodating, and PHP by all means is, you can have a mixed-EOL file look perfectly cool with the following command:

:match Invisible /\r$/

Or in newer versions of VIM 7.4+

:match Ignore /\r$/

To make things even worse, most GUI editors don't end a text file with a newline, and when a file does end with a newline, they show an empty line at the bottom. Since this is kind of annoying, most people will remove that empty line, which will result in a mixed-EOL file (and the dreadful ^Ms shown in Vim) if the file format was DOS.

If anyone knows how to make Eclipse or NetBeans honor the newline termination without showing the empty last line (as Vim cleverly does), please share your knowledge and you'll make a coder happy here. ;-)