The origin of the asymmetry goes back a ways into computing history.
Short version:
<CR> & <LF> (Carriage-Return and Linefeed)
==
\r & \n
Long version:
The first screens were basically digital versions of teletypes (TTY) and used control codes to generate similar behavior to printers. Carriage-return took the cursor (or print-head) to the start column. Linefeed advanced to the next row (on a screen) and fed the paper forward one line.
For printers, you had to do a paired <CR><LF>
or your output would not look right. On early screens, the issue still held true.
DOS (and sorta-Windows after) followed the old standard and saves text with <CRLF>
.
*NIX text (as most vi users are familiar) only uses <LF>
for efficiency.
To test in Windows, use Word/Wordpad and save a few lines of text "as type: Text - MS-DOS format". Then open that same file in Notepad. It should look normal. Then save the same file in Word/Wordpad "as type: Text". Notepad will ignore all newlines and run the lines together. [Notepad's text format defaults to the \r\n
combination while Word/Wordpad default to \n
.]
\r is the code equivalent of <CR>
\n is the code equivalent of <LF>
And in my (very limited) experience with vi, it would try to "fix" the <CRLF>
combination from my DOS text editor. vi ended up removing one character, replacing with <NUL>
. A big part of the reason I stopped using vi.