Removing ctrl M (^M) from files in vi

It’s a common thing to open a file on linux and discover it was flooded with ^M symbols after being editted in windows by some windows user.

The ^M symbol is pretty harmless usually (it is the representation of alternate CR carriage return or move to beginning of line). An old IBM /PCDOS artefact not shared with unix as a requirement for newline.

In vi or vim use the following keystrokes to remove the ^Ms. NOTE the ^V is an escape so will not show in your vimĀ 

:%s/^V^M//g

nJoy;

Leave a Reply

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