Enter key is different from Carriage Return (CR)

newlinesspecial charactersterminalvim

Many webpages said that ASCII code for enter key is 13(0d).
Enter key is considered as Carriage Return (CR).
Now let's make an experiment.
To open vim and just click enter key for three times ,do nothing more,then save the file as test.csv.

xxd  test.csv
0000000: 0a0a 0a 

My conclusions got.
The enter key's ascii value is 0a ,meaning newline ,it is different from Carriage Return (13 or 0d in ascii).
Is right or not?

Best Answer

Your terminal sends carriage return when you press Enter, and on Unix-like systems, the terminal driver translates that into line-feed ("newline").

That's the icrnl feature shown by stty -a, e.g.,

$ stty -a
speed 38400 baud; rows 40; columns 80; line = 0;
intr = ^C; quit = ^\; erase = ^H; kill = ^U; eof = ^D; eol = <undef>;
eol2 = <undef>; swtch = <undef>; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R;
werase = ^W; lnext = ^V; flush = ^O; min = 1; time = 0;
-parenb -parodd cs8 -hupcl -cstopb cread -clocal -crtscts
-ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr icrnl ixon -ixoff
-iuclc -ixany -imaxbel -iutf8
opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0
isig icanon iexten echo echoe echok -echonl -noflsh -xcase -tostop -echoprt
echoctl echoke

Programs (even shell scripts) can turn that off to read the actual carriage return character to distinguish it from ControlJ (line feed).