Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學
您现在的位置: Windows教程網 >> Windows教程 >  >> Linux 系統教學 >> 關於 Linux

Windows 檔案在 Ubuntu 顯示亂碼?vim 設定 fileencodings 自動識別 GBK/UTF-8

編輯:關於 Linux

Windows 預設編碼 GBK,Ubuntu 預設 UTF-8,跨平台開啟原始碼常見中文亂碼。解法:安裝 vim,編輯 ~/.vimrc 設定 fileencodings 優先順序 (utf-8,ucs-bom,gb18030,gbk,gb2312,cp936),Vim 將依序嘗試解碼自動識別正確編碼。同時設定 termencoding=utf-8、encoding=utf-8 確保內部處理與顯示一致。附贈常用 set nu、syntax on、set autoindent 等實用配置。

~/.vimrc 關鍵配置

set fileencodings=utf-8,ucs-bom,gb18030,gbk,gb2312,cp936
set termencoding=utf-8
set encoding=utf-8
set nu
syntax on
set showmode
set autoindent

設定生效後,Vim 開啟 GBK 編碼檔案將自動轉碼顯示正常中文,儲存時可選擇保留原編碼或轉存為 UTF-8,徹底解決跨平台亂碼困擾。

Copyright © Windows教程網 All Rights Reserved