When I am editing source files using vim and other editors sometimes at the end of the line I get these ^M characters at the end of each line. I think that it has something to do with editing a file in windows and then in linux. How can I remove all of these automatically?
+9
A:
There's a program called dos2unix that should strip those for you. Windows uses different line-ending characters which is why that happens.
Adam Lassek
2009-07-10 16:51:17
+13
A:
As a command, type
:%s/^M$//
(To get ^M, press ^V ^M, where ^ is CTRL on most keyboards)
Tobias Baaz
2009-07-10 16:51:58
also, :%s/\r$// to avoid the ^V^M hassle
glenn jackman
2009-07-11 13:53:04
didn't know that glenn, thanks for the tip
Tobias Baaz
2009-07-12 19:38:26
+1
A:
If you're FTPing these files from one box to another make sure to use ASCII transfers.
Spencer Ruport
2009-07-10 16:52:46
+1
A:
I tend to run afflicted files through fromdos
before reopening them. fromdos
is part of the tofrodos package.
Ted Percival
2009-07-10 22:10:08
+9
A:
You can do this:
:set fileformats=dos
It will hide the ^M
's, without touching the file.
jqno
2009-07-10 22:16:22