Use vim to remove ^M end of line characters

Sometimes, when you open a file in vim, the end-of-line (EOL) characters are messed up. You'll especially see this if you move a file from Windows to Unix.  You'll see a ^M at the end of each line. How do you remove all of these ^M characters from vim?
:%s/^M//g
The most difficult part of this is entering the control character.  You type ^V to get that, making the actual keys you press this:
:%s/<control>V<control>M//g
Breaking it down:
  • :%s - search and replace using regular expressions
  • ^M - the control V - control M characters
  • g - global replace, ie replace all
 

Established 2005 · Databasically © 2016