www.ntnu.no *
INFOWEB >  programs >  unix  > Using UTF-8 in UNIX-terminals and programs
Verktøy
Du kan legge til kommentarer
Eller sende denne artikkelen
Les artikler skrevet av livermor
Brukervurdering
Hvor mye hjelp var det i denne artikkelen?
Mye Noe Lite
Forhåndsvisning
Du trenger ikke en 'utskriftsvennlig side' for å skrive ut denne siden. Forklaring
Innhold

Using UTF-8 in UNIX-terminals and programs

If you want to use UTF-8 in your terminal emulator, it has to support UTF-8 and a system with UTF-8-locales installed. Locales are definitions for date, language, timezone settings, currency and most user defined parameters. Most GNU/Linux-distributions have UTF-8-locales installed.

When logging onto servers like login.stud.ntnu.no with UTF-8 you have to configure your terminalemulator first. In PuTTY you have to go to the Translation under the Category-part and choose UTF-8 in the list Character sets translation on received data. uxterm and urxvt use UTF-8 as default, and in Gnome Terminal you might have to change the settings in the menu Terminal-Choose character set-UTF-8.

You have to tell the system you want to use UTF-8-locales after you've logged in. You can check to see what locale you're using with locale

konsoll #1
gaupe:~$ locale
LANG=en_US
LC_CTYPE=nb_NO
LC_NUMERIC=nb_NO
LC_TIME=nb_NO
LC_COLLATE="en_US"
LC_MONETARY="en_US"
LC_MESSAGES="en_US"
LC_PAPER="en_US"
LC_NAME="en_US"
LC_ADDRESS="en_US"
LC_TELEPHONE="en_US"
LC_MEASUREMENT="en_US"
LC_IDENTIFICATION="en_US"
LC_ALL=

To change the locales, you use the command export. You will want to change LANG and LC_ALL on gaupe like this:

konsoll #2
gaupe:~$ export LANG=en_DK.UTF-8
gaupe:~$ export LC_ALL=en_DK.UTF-8
gaupe:~$ locale
LANG=en_DK.UTF-8
LC_CTYPE="en_DK.UTF-8"
LC_NUMERIC="en_DK.UTF-8"
LC_TIME="en_DK.UTF-8"
LC_COLLATE="en_DK.UTF-8"
LC_MONETARY="en_DK.UTF-8"
LC_MESSAGES="en_DK.UTF-8"
LC_PAPER="en_DK.UTF-8"
LC_NAME="en_DK.UTF-8"
LC_ADDRESS="en_DK.UTF-8"
LC_TELEPHONE="en_DK.UTF-8"
LC_MEASUREMENT="en_DK.UTF-8"
LC_IDENTIFICATION="en_DK.UTF-8"
LC_ALL=en_DK.UTF-8
You might have to put the export-commands in .bashrc. That way you will not have to write them each time you log on. It looks a bit weird that you want to have English like they speak it in Denmark... But this just means that you want English language with nordic timezone, currency and other things that are area-specific. If you want your programs in Norwegians instead of in English, use nb_NO.UTF-8.

vim and UTF-8

vim uses UTF-8 internally, and converts between character sets when reading and writing files. You can instruct vim to use UTF-8 by default (unless it detects otherwise) by putting the following in your .vimrc:

kode #1
set fileencoding=utf-8
set encoding=utf-8
set termencoding=utf-8

UTF-8 and emacs

Emacs on login.stud.ntnu.no supports UFT-8. If your version doesn't, you probably have to install mule (sudo aptitude install mule-ucs) and add the following to your .emacs (or .xemacs/custom.el):

kode #2
(prefer-coding-system 'mule-utf-8)
(setq locale-coding-system 'mule-utf-8)
(set-terminal-coding-system 'mule-utf-8)
(set-keyboard-coding-system 'mule-utf-8)
(set-selection-coding-system 'mule-utf-8)

Using UTF-8 with irssi

If you want to use UTF-8 with irssi, you type the following into your terminal:

kode #3
/set term_charset UTF-8
Newer versions of irssi allow customizing the character sets of different channels with the command recode:
kode #4
/set recode_out_default_charset UTF-8
Then, for each channel you want UTF-8 in:
kode #5
/recode add UTF-8
For further explanation, see
kode #6
 /help recode 
.

mutt and UTF-8

If you use mutt for e-mail, you can configure the .muttrc-file to use UTF-8:

kode #7
set charset=utf-8
set send_charset=utf-8
You also have to make sure your editor for mutt uses UTF-8. So for vim that means you have to add the following lines to .vimrc:
kode #8
au BufNewFile,BufRead mutt*    set tw=77 ai nocindent fileencoding=utf-8

UTF-8 and pine

The e-mail client pine does not support UTF-8.

It is possible, if you really want to, to use UTF-8 in pine. You have to use a program that translates everything going in and out so that pine still thinks its UTF-8-less:

kode #9
user@gaupe:~$ luit -encoding 'ISO-8859-1' pine
Unfortunately, this is not an optimal solution and it is preferable to use an e-mail client that really supports UTF-8.


Språk: en flag_no Kommentarer: 0 Aid: 548 Brukervurdering:
 
 
Sist oppdatert: 2007-08-01 Forfatter: livermor Lest: 372 ganger