Chapter 08 · Editing and files编辑与文件編輯與檔案
Encodings and line endings编码与行尾編碼與行尾
Supported charsets
- Unicode: UTF-8 (with and without BOM), UTF-16 LE / BE, ASCII.
- Chinese: GB2312, GBK, GB18030, Big5.
- Japanese / Korean: Shift-JIS, EUC-JP, EUC-KR.
- Western: ISO-8859-1 through ISO-8859-16, Windows code pages 1250–1258, KOI8-R.
More than forty charsets in total.
Detection order
- A BOM, if present, decides the encoding outright.
- Without a BOM, byte statistics are analysed to choose the most likely charset.
- GB2312 is distinguished from GBK by checking whether all byte pairs fall inside the strict GB2312 range.
Detection can be wrong on short files or files that mix languages. That is a property of the bytes, not a bug you can always avoid.
Switching and reloading
- Click the encoding segment in the status bar to pick a charset for the current document.
- “Reload with encoding” re-reads the file from disk using the chosen charset.
- Switching the encoding without reloading reinterprets the existing buffer; use reload when the file is still correct on disk.
Batch conversion
Several open documents can be converted to one target charset in a single operation — useful when a repository mixes GBK and UTF-8 files.
Line endings
LF and CRLF are detected on open and shown in the status bar. Converting rewrites the buffer's terminators; the change is applied on save. Mixed files are normalised to the selected style.
BOM policy
BOM presence is preserved on save. Repeated saves never stack additional BOM bytes, and UTF-8 files without a BOM stay without one.
Garbled text checklist
- Try GB18030 first for Chinese files; it is a superset of GBK and GB2312.
- If the file opens as pairs of CJK characters, UTF-16 LE is a likely candidate.
- If punctuation is correct but some characters are wrong, the file may genuinely be mixed-encoding.
支持的字符集
- Unicode:UTF-8(含/不含 BOM)、UTF-16 LE / BE、ASCII。
- 中文:GB2312、GBK、GB18030、Big5。
- 日韩:Shift-JIS、EUC-JP、EUC-KR。
- 西文:ISO-8859-1 至 ISO-8859-16、Windows 代码页 1250–1258、KOI8-R。
合计 40 种以上。
检测顺序
- 存在 BOM 时,直接按 BOM 判定。
- 无 BOM 时分析字节统计,选出最可能的字符集。
- 通过检查字节对是否全部落在严格 GB2312 范围内,区分 GB2312 与 GBK。
短文件或混合语言文件可能检测错误——这是字节本身的歧义,不可能永远消除。
切换与重新加载
- 点击状态栏编码片段为当前文档选择字符集。
- 「按指定编码重新加载」会用所选字符集重新从磁盘读取。
- 只切换编码是重新解释当前缓冲区内容;磁盘文件仍正确时应使用重新加载。
批量转换
可把多个已打开文档一次性转换到同一目标字符集,适合仓库里 GBK 与 UTF-8 混杂的情况。
行尾格式
打开时检测 LF 与 CRLF 并显示在状态栏。转换会重写缓冲区的换行符,保存时落盘;混合行尾会统一为所选风格。
BOM 策略
保存时保持原有 BOM 状态:重复保存不会叠加 BOM 字节,原本无 BOM 的 UTF-8 文件也不会被加上。
乱码排查
- 中文文件优先试 GB18030,它是 GBK 与 GB2312 的超集。
- 如果显示成一对对的生僻汉字,多半是 UTF-16 LE。
- 如果标点正常、个别字符错误,文件可能是真正的混合编码。
支援的字元集
- Unicode:UTF-8(含/不含 BOM)、UTF-16 LE / BE、ASCII。
- 中文:GB2312、GBK、GB18030、Big5。
- 日韓:Shift-JIS、EUC-JP、EUC-KR。
- 西文:ISO-8859-1 至 ISO-8859-16、Windows 程式碼頁 1250–1258、KOI8-R。
合計 40 種以上。
檢測順序
- 存在 BOM 時,直接按 BOM 判定。
- 無 BOM 時分析位元組統計,選出最可能的字元集。
- 透過檢查位元組對是否全部落在嚴格 GB2312 範圍內,區分 GB2312 與 GBK。
短檔案或混合語言檔案可能檢測錯誤——這是位元組本身的歧義,不可能永遠消除。
切換與重新載入
- 點擊狀態列編碼片段為當前文件選擇字元集。
- 「按指定編碼重新載入」會用所選字元集重新從磁碟讀取。
- 只切換編碼是重新解釋當前緩衝區內容;磁碟檔案仍正確時應使用重新載入。
批量轉換
可把多個已開啟文件一次性轉換到同一目標字元集,適合倉庫里 GBK 與 UTF-8 混雜的情況。
行尾格式
開啟時檢測 LF 與 CRLF 並顯示在狀態列。轉換會重寫緩衝區的換行符,儲存時落盤;混合行尾會統一為所選風格。
BOM 策略
儲存時保持原有 BOM 狀態:重復儲存不會疊加 BOM 位元組,原本無 BOM 的 UTF-8 檔案也不會被加上。
亂碼排查
- 中文檔案優先試 GB18030,它是 GBK 與 GB2312 的超集。
- 如果顯示成一對對的生僻漢字,多半是 UTF-16 LE。
- 如果標點正常、個別字元錯誤,檔案可能是真正的混合編碼。