DarkMatter in Cyberspace
  • Home
  • Categories
  • Tags
  • Archives

Add Chinese Character Display Support on Linux


Step 1: Can the termianl display unicode character?

If this terminal is set to display UTF-8 character?

$ echo -e '\xe2\x82\xac'
€

If the euro sign can't be displayed, ssh to this host via another host which can display UTF-8 character, and run this command remotely via ssh. If the euro sign displayed, it's verified your terminal do not support UTF-8, you have to install another UTF-8 supported terminal.

Ref: "My terminal doesn't support UTF-8" in Locale of ArchLinux Documentation.

Step 2: Can the editor display unicode character?

If you find Chinese characters can't be displayed correctly in vim, cat this file, if cat display them correctly, that's a problem in your settings of vim, jump to section 'vim settings'.

If cat can't display it, too, that's the system's problem, jump to section 'Add system language support'.

vim settings

Run :set encoding=utf-8 in vim editor. If it works, add this setting into vim settings file: echo 'set encoding=utf-8' >> /usr/share/vim/vimrc.

Here the position of system-wide vim setttings (/usr/share/vim/vimrc) is specified by vim --version | grep 'system vimrc file' and vim --version | grep 'fall-back for $VIM'.

System language support

Ubuntu

List all locales installed on the system:

$ locale -a

If there's no 'zh_CN.utf8', that's why the Chinese character can't be displayed in shell (not in vim). Run sudo locale-gen zh_CN.utf8.

Test result: export LC_ALL=en_US.utf-8.

Notice LC_ALL=en_US (without .utf8) can't display UTF-8 charaters correctly! Enable it permanently: add "LANG=en_US.UTF-8" or "LC_ALL=en_US.UTF-8" into /etc/default/locale, and refresh it: sudo locale-gen.

Arch Linux

$ sudo pacman -Syu vim  // install vim and xxd

Convert file encodings

$ iconv -l | GBK
$ iconv -l | UTF-8
$ iconv -f gbk -t utf-8 <filename>


Published

May 1, 2014

Last Updated

May 1, 2014

Category

Tech

Tags

  • Chinese 8
  • Linux 158
  • 乱码 1
  • 汉字 3
  • 中文 5

Contact

  • Powered by Pelican. Theme: Elegant by Talha Mansoor