Removing DOS linebreaks from your files using Vim

Posted in dev-sys on December 3, 2007

This morning I'm debugging an issue on a script that gets cronned every minute. I've a shell open on the server and the file in question open using Vim and I notice each line has a trailing ^M.... Aargh the dreaded DOS linebreak.

Dusting off my rusty vim-foo I simply do a search and replace using Vim without having to exit the file.

The command is:

:%s/^M//g

Job done, well actually, no, there is still an issue with the script, but now I at least know that ^M is not the culprit.

Note: To get the ^M I did NOT type a caret and M, I typed Ctrl-V then Ctrl-M

Comments (0)