PDA

View Full Version : [SOLVED] The <CR> button?



Tinker Tantrum
October 31st, 2011, 07:08 PM
Sorry for my noobness in advance: I was wondering what <CR> stands for in various Vim manuals, etc. I keep seeing <CR>, but have no idea if that is a key sequence or abbreviation or what!

Devi1903
October 31st, 2011, 07:13 PM
Carriage Return if i am not mistaken

Telengard C64
October 31st, 2011, 07:15 PM
Possibly refers to carriage return, aka enter. Just guessing though.

edit

I think maybe it refers strictly to the ASCII character for carriage return. Depending on your operating system, this may or may not be the same as the code(s) generated by pressing the Enter key.


*23.1* DOS, Mac and Unix files
Back in the early days, the old Teletype machines used two characters to
start a new line. One to move the carriage back to the first position
(carriage return, <CR>), another to move the paper up (line feed, <LF>).
When computers came out, storage was expensive. Some people decided that
they did not need two characters for end−of−line. The UNIX people decided
they could use <Line Feed> only for end−of−line. The Apple people
standardized on <CR>. The MS−DOS (and Microsoft Windows) folks decided to
keep the old <CR><LF>.

http://www.eandem.co.uk/mrw/vim/usr_doc/index.html

dave0109
October 31st, 2011, 07:27 PM
Yes, CR = Carraige Return. It basically means press the <enter> or <return> key.

UNIX distinguishes because lines are ended with just a CR on UNIX, but Windows uses CR followed by LF (Line Feed).

sisco311
October 31st, 2011, 07:28 PM
Yep, it's Carriage Return (ASCII 13). Often written as ^M or \r. CRs are found just before newlines in text files generated by DOS/Windows apps.

In vim, type :help keycodes. ;)

sisco311
October 31st, 2011, 07:31 PM
Yes, CR = Carraige Return. It basically means press the <enter> or <return> key.

UNIX distinguishes because lines are ended with just a CR on UNIX, but Windows uses CR followed by LF (Line Feed).

Hmmm, there are three different kinds of line endings in common use:


Unix systems use Line Feeds (LFs) only.
MS-DOS and Windows systems use CR-LF pairs.
Old Macintosh systems use CRs only.

Tinker Tantrum
October 31st, 2011, 07:54 PM
Ah ha. Yes. You are right. You are "all" right. Thank you!!

anewguy
November 1st, 2011, 04:19 AM
And where does it come from? A typewriter. In the manual days you actually had to return the carriage back manually in order to start typing at the beginning. A line feed was accomplished in conjunction with this depending on how you did the return. When typewriters went electric, eventually the carriage no longer moved, just the print head. They needed something for everyone to understand who was used to the old way. CR was introduced as the abbreviation for a carriage return. When this is stored in a file at that time CR also represents an actual character. LF was introduced as the abbreviation for a line feed. Some OS's, when dealing with text files, take a CR as a CR/LF combination, others as just a CR. CR or a null was sometimes used to indicate the end of a "line" record in a text file as well.

Just part of what it's all about - all of that for a simple pair of characters, eh?

Dave ;)

sisco311
November 1st, 2011, 07:55 AM
http://www.youtube.com/watch?v=FHHQ4GDjGgM&feature=related

:-\"

anewguy
November 1st, 2011, 09:21 AM
http://www.youtube.com/watch?v=FHHQ4GDjGgM&feature=related

:-\"

Admittedly that last carriage return is backwards, but it is hilarious!

Thanks for a good laugh!

Dave ;)

dave0109
November 1st, 2011, 11:15 AM
Hmmm, there are three different kinds of line endings in common use:

Oops, you're right. Don't know what I was thinking, I deal with this stuff every day!

nothingspecial
November 1st, 2011, 11:24 AM
http://www.youtube.com/watch?v=fhhq4gdjggm&feature=related

:-\"

lol

lisati
November 1st, 2011, 11:30 AM
Speaking of typewriters & changes in technology: http://www.youtube.com/watch?v=9vuDMInQMYQ

Jonathan L
November 1st, 2011, 11:58 AM
Sorry for my noobness in advance: I was wondering what <CR> stands for in various Vim manuals, etc. I keep seeing <CR>, but have no idea if that is a key sequence or abbreviation or what!

Hi Tinker

Most people have never seen one, but you have to remember interactive computing (ie, after punch cards) used machines like the ASR-33 Teletype, a remote control typewriter.

I've attached a close crop of the picture on Wikipedia (http://en.wikipedia.org/wiki/ASR-33_Teletype), you'll see the keys marked "line feed" and "return", whcih (as others have said), moved the paper up and the printing head to the left, respectively. Remember these are pre-microprocessor, and the ASCII decoding is done with little metal cogs and bars, frankly amazing if you ever see one work.

It's my opinion that one of the many small but very clever things about the design of Unix was the separation between a print format, designed to go to a printer (which would clearly require separate linefeeds and carriage returns) and a storage format, which would benefit from the saving of space and the simplicity of processing. It's obvious that you can simulate a lifefeed with a carriage return and the appropriate number of spaces, but not the other way around, which I believe is the explanation for why Unix uses a single linefeed rather than a carriage return in files, and I believe the carriage return is normally first because it takes longer to do on a teletype, and I believe the motions overlap.

Kind regards,
Jonathan.

anewguy
November 1st, 2011, 09:39 PM
Just a side note: the CR was never intended to do an automatic line feed. LF was created for that. Long prior to teletypes, typewriters, as I mentioned before, had a manual carriage. Eventually there was a lever that you pushed to return the carriage to printing space 1. Pushing that lever further as you returned the carriage also did a line feed.

There have been many things that have required a CR without the LF. Even the old character based mainframe printers sometimes used just the CR without doing a LF. An exteremly interesting, and extreme ribbon mangler and time user, was to print posters on a character based mainframe printer. You ended up with long strips that you put side by side and had a huge poster - from several feet away they looked photographic. This was accomplished by several CRs without LF's so characters could be overwritten with another character until the appropriate shading, etc., occured for what was needed for the poster.

Just a simple example. Don't confuse record terminators in files, which vary from OS to OS, with the actual function of a CR and LF. Even with some of the old character based terminals CR was used to indicate return the cursor to the beginning of the current line, and LF to move down 1 line.

Dave ;)