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.
Any suggestions?
2 Answers
^M usually appear when the file is inconsistent with regards to the line terminators used. Try the following:
- Create
testfileusing vim with a few random lines, and write it in dos mode. Then run (hope you have cygwin installed):
sed '2s/.$//' testfile > corruptfileThis will remove the last character of the second line, creating an inconsistency in the line terminators used.
- Open
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:
:% s/^M//g The ^M is produced by pressing: Ctrl+v <Enter>
Then write back the file in the desired format:
:set ff=dos :w 8The 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.
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 5