Why is ^M
used to represent a carriage return in VIM and other contexts?
My guess is that M
is the 13th letter of the Latin alphabet and a carriage return is \x0D
or decimal 13
. Is this the reason? Is this representation documented anywhere?
I notice that Tab is represented by ^I
, which is the ninth letter of the Latin alphabet. Conversely, Tab is \x09
or decimal 9
, which supports my theory stated above. However, where might this be documented as fact?
Best Answer
I believe that what OP was actually asking about is called Caret Notation.
The full list of ASCII control characters along with caret notation can be found here
Regarding vim and other text editors: You'll typically only see ^M if you open a Windows-formatted (CRLF) text file in an editor that expects Linux line endings (LF). The 0x0A is rendered as a line break, the 0x0D right before it gets printed as ^M. Most of the time, editor default settings include 'automatically recognize line endings'.