I use Vim 7.3 under Windows 7 and have experienced a problem. Symbols
^M are not disappearing despite any my efforts,
:e ++ff=dos does not help.
Super User is a question and answer site for computer enthusiasts and power users. It only takes a minute to sign up.Sign up to join this community
^M usually appear when the file is inconsistent with regards to the line terminators used. Try the following:
testfileusing vim with a few random lines, and write it in dos mode.
Then run (hope you have cygwin installed):
sed '2s/.$//' testfile > corruptfile
This will remove the last character of the second line, creating an inconsistency in the line terminators used.
corruptfilewith vim. ^M symbols will appear so that you are made aware of the inconsistency.
In real life, programs that have been written with a single type of line-terminator in mind may produce such inconsistencies. While these inconsistencies seem innocent, they may cause you problems with other programs. E.g. subversion does not allow file with inconsistent line terminators to be added to a repository. Other programs may just fail silently.
To make ^M dissapear just make a global replacement:
^M is produced by pressing:
Then write back the file in the desired format:
:set ff=dos :w
The character that vim displays as ^M is
CR (carriage return, ASCII character 13). Windows uses both
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
If you open a text file created on a Windows computer on a Linux box, you may see trailing
CR characters in each line. There are several ways to remove them. One is to replace them in vim as m000 suggested, another would be to
recode the file:
recode ibmpc..latin1 SOME.TXT