Removing ^M characters on ubuntu in VIM

Posted on Jun 20th, 2010

It took me a while to figure out how to get rid of pesky ^M characters in VIM on ubuntu. ^M in VIM can be manipulated as it is an \r character. Often times other developers would edit python files in gedit or notepad and ^M characters would be inserted. I could not simply

as "^M" was not a recognized character.

The fix is really quite simple and I was frustrated it took me so long to find, but in case it gets to anyone else – the ^M is a line feed character that is inserted by gedit(among other editors) sometimes. In VIM, it shows up as ^M, but it is actually a "\r" character. So, doing a replace for \r characters will remove the ^M

NEXT | Replace a String in Multiple Files in Linux Using Grep and Sed
PREVIOUS | Dijkstra's Algorithm - Shortest Path
All Posts