Tuesday, October 4, 2011

Vim, IRC Irssi, PuTTY (Pietty), Screen and Unicode UTF-8

Vim, IRC Irssi, PuTTY (Pietty), Screen and Unicode UTF-8

For some reason it seems to be non-trivial to get Unicode to work in console apps, so I decided to make an illustrated guide about Vim, Irssi, PuTTY and GNU screen. Hope it helps.

Note: you needn't be using GNU screen to follow this guide.

Configuring FreeBSD
要將 FreeBSD 的系統改為 UTF8 只需修改下面這個檔案

# vi /etc/csh.cshrc
### enable utf-8 support
setenv LC_ALL en_US.UTF-8
setenv LANG en_US.UTF-8
#setenv LC_ALL zh_TW.UTF-8
#setenv LANG zh_TW.UTF-8

### Add these two lines for ls color.
setenv LSCOLORS ExGxFxdxCxDxDxBxBxExEx

setenv TERM screen-256color

改完後先登出後再登入輸入 locale 就可看到如下的系統預設語系已經不是 C

# locale


To see a list of locales supported by your system:
# ls /usr/share/locale

(If you’re not using screen, you can skip to the PuTTY section.)

Configuring screen to use UTF-8

This one is simple but important. If you’re using GNU screen, make sure to start it with -U parameter to enable unicode mode. This does not work when attaching to an existing session, you need to start a new session.

Put following line in ~/.screenrc file:
# to configure how screen looks like.
hardstatus alwayslastline " %{= W} %-Lw %{= KY}%n%f %t%{-}%+Lw %=| "
# to avoid ncurses menu messed up when you are trying to run make install command.
cjkwidth off
# Always start screen with utf8 enabled. (Alternative method is to run screen with -U parameter)
defutf8 on
#utf8 on on

Note: when you are trying to install a FreeBSD port, you run make config install command, the ncurses menu messed up. That is because you have set cjkwidth on (and also "treat CJK ambiguous characters as wide" in putty). Set cjkwidth off, and uncheck the "treat CJK ambiguous characters as wide" checkbox.

Note: cjkwidth 平常保持 off,只有在要看 日文、韓文、或 Big5 時,才需要把 cjkwidth on,注意,PuTTY (PieTTY) 的 "treat CJK ambiguous characters as wide" 也會有影響。

Note: 在 screen 裡面時,用以下指令來切換 cjkwidth:
Ctrl-A :cjkwidth on
Ctrl-A :cjkwidth off

Running screen in unicode mode (with -U parameter):
# screen -U

進入 screen 的 Unicode 模式,打 screen -U,或在 ~/.screenrc 設定檔裡寫 defutf8 on
(日後若要 attach 回 screen 則用 screen -rU )

Ctrl + B --> switch to Big 5
Ctrl + U --> switch to UTF-8

Ctrl-A + D --> Detach

# screen -r --> Attach

Ctrl-A + C --> create a new window
Ctrl-A + n --> next window
Ctrl-A + p --> previous window

Configure PuTTY to use Unicode UTF-8
Configuring PuTTY to use UTF-8 is a three-step process:

[] PuTTY > Option > more options > Windows > Translation > Received data assumed to be in which character set: UTF-8

[] uncheck "treat CJK ambiguous characters as wide" checkbox.

[] Apply the settings.

Note: 只有在要看 日文、韓文、或 Big5 時,才需要把 cjkwidth on.

Configuring Vim to use UTF-8

Edit your .vimrc settings file to include the following lines:

// 讓 vim可以正確開啟下列表編碼的檔案
set fileencodings=utf-8,big5,euc-jp,gbk,euc-kr,utf-bom,iso8859-1

// 讓 vim在編輯新檔案的時候預設使用 utf-8 作為encoding
set encoding=utf-8

Configuring Irssi to use UTF-8

If you try to input UTF-8 into Irssi now…

it won’t work properly:

You’ll need to set up Irssi for use with UTF-8 first by setting the term_charset to utf-8:

/set term_charset utf-8

A bit late but nice guide. By the way even though doing all that you may experience some problems like the input looks fine but after pressing enter it turns into question marks. In order to fix that you have to do:

/set recode_fallback utf-8

Trying again…

Yay, it works!

And you can even talk to mIRC users:
(if they speak your language…)

Irssi Set up environment encoding Ensure that your terminal and shell use an encoding that supports Japanese characters. Use echo $LANG in a terminal to check. Any UTF-8 locale, such as en_US.UTF-8 works. Also, if you use Irssi in GNU Screen and/or...










No comments: