Search

2/08/2008

Newline - Wikipedia, the free encyclopedia

Newline - Wikipedia, the free encyclopedia

Systems based on ASCII or a compatible character set use either LF (Line feed, 0Ah) or CR (Carriage Return, 0Dh) individually, or CR followed by LF (CR+LF, 0Dh 0Ah); see below for the historical reason for the CR+LF convention. These characters are based on printer commands: The line feed indicated that one line of paper should feed out of the printer, and a carriage return indicated that the printer carriage should return to the beginning of the current line.

* LF: Multics, Unix and Unix-like systems (GNU/Linux, AIX, Xenix, Mac OS X, etc.), BeOS, Amiga, RISC OS, and others
* CR+LF: DEC RT-11 and most other early non-Unix, non-IBM OSes, CP/M, MP/M, DOS, OS/2, Microsoft Windows
* CR: Commodore machines, Apple II family and Mac OS up to version 9

dos/unix - Everyday Work
Windows/Dos 下文字檔案是用 CR LF 兩個字元 (ASCII 13 的 \r, 和 ASCII 10 的 \n) 代表分行;程式看到這兩個字元連在一起,就該知道要換行。在 Un*x 下,分行則只用 LF 來代表;程式只需要看到這一個字元就知道要換行。

在 vim 裡,用 set ff=unix 可以把文字檔改成 Un*x 用的格式 (set ff=dos 則改成 DOS 格式),執行後儲存就好了。

沒有留言: