Use vi / vim to remove ^M characters from files

Sometimes you’ll be handed a file from a Windows user and it will contain a bunch of “^M” characters at the end of every line.  Removing them is easy, just run the command:

:%s/^M//g

To get the “^M” properly, don’t type “^” and “M”.  Instead, type “ctrl + v”, then “ctrl + m”.

Leave a Reply

Your email address will not be published. Required fields are marked *