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

解決 Linux 終端機中文亂碼:SecureCRT、Vim 與 Locale 完整設定指南

編輯:Linux 教學

亂碼成因分析

使用 SecureCRT 提交 SVN 中文日誌時無法輸入中文。主要原因在於終端機編碼、Vim 編碼與系統 Locale 設定不一致。

SecureCRT 編碼設定

選項 → 會話選項 → 終端機 → 外觀 → 字元編碼,選擇 UTF-8。

Vim 編碼配置

在 ~/.vimrc 加入:

set fencs=utf-8,ucs-bom,shift-jis,gb18030,gbk,gb2312,cp936
set termencoding=utf-8
set encoding=utf-8
set fileencodings=ucs-bom,utf-8,cp936
set fileencoding=utf-8
set nohls
set nu
filetype on
syntax on
set tabstop=4
set shiftwidth=4
set autoindent
set smartindent
set showmatch
set ruler

環境變數 LANG 設定

臨時生效:

export LANG=zh_CN.UTF-8

永久生效:編輯 ~/.bash_profile,在末尾加入:

export LANG=zh_CN.UTF-8

重新啟動 SSH 客戶端即可自動載入。

常見亂碼場景與對策

  • 中文字元亂碼:安裝中文控制台(如 zhcon)或設定 export LANG=zh_CN.UTF-8。
  • Oracle 安裝介面亂碼:執行 export LANG=en_US 切換英文環境。
  • 英文字元亂碼:通常因 cat 二進位檔案導致,執行 reset 終端機重置。
  • 偽終端機亂碼:SSH 遠端 cat 核心轉儲檔案導致,reset 無效時,嘗試 tput sgr0 或 Ctrl+V Ctrl+N 恢復。

總結

統一 SecureCRT、Vim、Shell 環境編碼為 UTF-8,並正確設定 LANG 變數,可徹底解決 Linux 終端機中文輸入顯示亂碼問題。

Copyright © Windows教程網 All Rights Reserved