0.简介
在linux中vim查看一个windows下的文本文件, 经常在行尾有一个 ^m.
这其实是windows/linux/mac系统中文本换行不一致的原因导致的,
| 系统类别 | 文本换行符 | 转义字符 |
| windows | crlf | \r\n |
| linux | lf | \n |
| mac | cr | \r |
具体可查看 windows和linux换行规则的区别 .
这里需要介绍的是 ^m 类的符号是什么意思.
1. vim的脱字符表示法
ascii 0-31 部分的所有字符都是控制字符,不是可显示字符。为了在vim中显示出这些字符,将这些字符的编码加上 64 之后对应的全部为可打印字符,于是将 0-31 位置的字符,
用 ^ 跟转换之后对应的那个字符绑在一起当作一个字符显示出来,既简洁又实用,——是为“脱字符表示法”。
如:0x00 对应 ^@ (0 64),0x0d(回车)对应 ^m (13 64)等等
详细的列表可以通过在vim中 :help digraph-table 命令查看,具体如下(只列出了前33个)
char digraph hex dec official name ~
^@ nu 0x00 0 null (nul)
^a sh 0x01 1 start of heading (soh)
^b sx 0x02 2 start of text (stx)
^c ex 0x03 3 end of text (etx)
^d et 0x04 4 end of transmission (eot)
^e eq 0x05 5 enquiry (enq)
^f ak 0x06 6 acknowledge (ack)
^g bl 0x07 7 bell (bel)
^h bs 0x08 8 backspace (bs)
^i ht 0x09 9 character tabulation (ht)
^@ lf 0x0a 10 line feed (lf)
^k vt 0x0b 11 line tabulation (vt)
^l ff 0x0c 12 form feed (ff)
^m cr 0x0d 13 carriage return (cr)
^n so 0x0e 14 shift out (so)
^o si 0x0f 15 shift in (si)
^p dl 0x10 16 datalink escape (dle)
^q d1 0x11 17 device control one (dc1)
^r d2 0x12 18 device control two (dc2)
^s d3 0x13 19 device control three (dc3)
^t d4 0x14 20 device control four (dc4)
^u nk 0x15 21 negative acknowledge (nak)
^v sy 0x16 22 synchronous idle (syn)
^w eb 0x17 23 end of transmission block (etb)
^x cn 0x18 24 cancel (can)
^y em 0x19 25 end of medium (em)
^z sb 0x1a 26 substitute (sub)
^[ ec 0x1b 27 escape (esc)
^\ fs 0x1c 28 file separator (is4)
^] gs 0x1d 29 group separator (is3)
^^ rs 0x1e 30 record separator (is2)
^_ us 0x1f 31 unit separator (is1)
sp 0x20 32 space
................
2.文件转换命令
unix2dos