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?
The file in question was created in Windows and then copied over to Linux. ^M is the keyboard equivalent to \r or CTRL-v + CTRL-m in vim.
Use \r instead of \n . Substituting by \n inserts a null character into the text. To get a newline, use \r . When searching for a newline, you'd still use \n , however.
^M are the meta characters which entered your file when it was used in windows. the dos2unix command can fix this. dos2unix <filename> Follow this answer to receive notifications.
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
:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With