Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does ^M character mean in Vim?

Tags:

vim

unix

I keep getting ^M character in my vimrc and it breaks my configuration.

like image 443
Max Avatar asked Apr 30 '11 17:04

Max


People also ask

What is the M character in vim?

Show activity on this post. The character that vim displays as ^M is CR (carriage return, ASCII character 13). Windows uses both CR and LF (new line, ASCII character 10) to encode line breaks in text files. Linux/Unix use only LF to encode line breaks, and Mac OS uses only CR .

What is the M character in Linux?

Viewing the certificate files in Linux shows ^M characters appended to every line. 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.

How do I get rid of M in vim?

How can I remove ^M characters from text files? A. ^M are nothing more than carriage return, so it is easy to use the search and replace function of vim to remove them. That will do the job.

What does M mean in Unix?

Control M ( ^M) characters are introduced when you use lines of text from a windows computer to Linux or Unix machine. Most common reasons are when you directly copy a file from a windows system or submit form data copied and pasted from a windows machine.


1 Answers

Unix uses 0xA for a newline character. Windows uses a combination of two characters: 0xD 0xA. 0xD is the carriage return character. ^M happens to be the way vim displays 0xD (0x0D = 13, M is the 13th letter in the English alphabet).

You can remove all the ^M characters by running the following:

:%s/^M//g 

Where ^M is entered by holding down Ctrl and typing v followed by m, and then releasing Ctrl. This is sometimes abbreviated as ^V^M, but note that you must enter it as described in the previous sentence, rather than typing it out literally.

This expression will replace all occurrences of ^M with the empty string (i.e. nothing). I use this to get rid of ^M in files copied from Windows to Unix (Solaris, Linux, OSX).

like image 116
Tomasz Stanczak Avatar answered Oct 21 '22 19:10

Tomasz Stanczak