9

I am working with gVim in Windows, and when I open files edited by others I see ^M instead of newlines. I have tried using %s/^M/\n/g to replace all instances of ^M with a newline, but I keep getting the error: Pattern not found: ^M. I have also tried %s/^M/\r/g, but I receive the same error.

There are still several instances of ^M in the file, why can't Vim identify them?

Zach Wulf
  • 401
  • 2
  • 7
  • 18

2 Answers2

13

Press CTRLV before pressing CTRLM in your substitute command.

This allows you to escape the next control sequence properly.

Here are a couple links I found by googling: vim remove control m:

Community
  • 1
  • 1
jahroy
  • 22,322
  • 9
  • 59
  • 108
  • If you're using Cygwin, you can use the `dos2unix` or `unix2dos` command to convert newline chars. – jahroy Apr 11 '13 at 02:35
0

Are you sure it's carat-M and not ctrl-M? If it's carat-M (^M) then it will be two characters. If it's ctrl-M it will be one. If it's the latter, then here's your solution.

Community
  • 1
  • 1
Logan
  • 4,177
  • 3
  • 20
  • 35