April 14th, 2015, 06:36 PM
Removing ^M from file via Vi (Problem)
I am trying to remove the character '^M' from a text file I have - I've tried using :%/^M//g and other combinations, to which Vi responds E486: pattern not found: ^M.
Here is a screen shot of the response and evident ^M's in my file.
Any help would be appreciated!
April 14th, 2015, 07:32 PM
See how the ^Ms are colored unlike everything else? vim is telling you that those aren't literally the characters "caret + capital 'M'" but a control character: ASCII 13 (thus the M). Which is a \r.
It may be reading the file using Unix line endings. Which there don't seem to be any of. What happens if you use the command ":e ++ff=mac"?
April 14th, 2015, 08:25 PM
When I use ":e ++ff=mac" I get this occur:
Originally Posted by requinix
However when i do :wq to save it, then reopen the file I get the original format of the document with the ^M in it. It doesn't save as a file with the correct formatting like shown in the picture above (ff=mac applied).
April 15th, 2015, 02:32 PM
That command just reloads the file with a different line endings format applied. Doesn't actually change the file.
Your vim seems to be attempting a set of line endings that doesn't include "mac", which is typically what happens for a vim running on Linux or Windows.
Take a look here to find out what's going on, and how to convert the file.