[UFO Chicago] another very newbie 'nix question

Nick Moffitt nick@zork.net
Sat, 26 Jan 2002 17:49:52 -0800


begin  John Kilbourne  quotation:
> What are all the ^M 's that are at the ends of the lines in text
> files I take from windows (made in gvim) and put on unix or linux?
> It must be some kind of newline thing; do they do any harm?

	The ASCII character set lists names for a number of control
characters, but does not specify which ones are ACTUALLY used for
what.  There are two characters (^J and ^M) that are referred to as
Carriage Return and Linefeed.  

	In the days of the old slow printer terminals, it was found
that it took twice as long for the print head to swish back over to
the left hand side of the page as it did for the head to move to the
right one character.  The correct solution would have been to buffer
your printing while your head moved back, but instead the practice of
using TWO characters to represent what happens when you hit the Return
key was started.  

	Thus, to prevent the first character of the next line from
being printed in the middle of the page on the head's trip back to the
left, they decided that you would move down and to the left by sending
the terminal a carriage return to send the head left, and then while
it was doing that you could safely send a SEPARATE character
(linefeed) to move the paper up one (or the cursor down one, depending
on your perspective).

	Now DOS is one of the operating systems that encodes this
directly into the file format.  Thus, all ascii files on DOS use the
CRLF combination.  Macintoshes and Unix machines, however, store only
one of these in the file, and translate it to two if they know they're
sending to something that wants both.  Sadly, however, Macs use ^M and
Unix uses ^J.

	Fortunately, it's pretty straightforward in vim to change
between dos and unix format.  I think it's ":set fileformat=unix" and
":set fileformat=dos".  You can probably get more info with ":help
fileformat"

-- 
INFORMATION GLADLY GIVEN BUT SAFETY REQUIRES AVOIDING UNNECESSARY CONVERSATION
 
	01234567 <- The amazing* indent-o-meter! 
        ^	    (*: Indent-o-meter may not actually amaze.)