Character encoding

James Wilkinson fedora at aprilcottage.co.uk
Tue Sep 9 20:26:45 UTC 2008


Björn Persson wrote:
> There's a whole set of environment variables that control the locale. The 
> command "locale" displays them all, but normally you'd just set LANG. You 
> should probably define LANG for the whole system in /etc/sysconfig/i18n.
> 
> I don't know Vim but I'd guess that it uses the locale encoding as a default.

Firstly, Red Hat spent quite some time getting Red Hat Linux (the
predecessor of Fedora) to work well with UTF-8, and to use this as a
default. If you haven’t done anything to change how Fedora encodes text,
the chances are that it’s encoded as UTF-8 (or US-ASCII, which is the
common subset to UTF-8 and most Western encodings).

Secondly, for Canadian French and English, you’d probably get away well
with Latin 1 (= ISO-8859-1), which should contain all the characters you
need¹.

Thirdly, the main encoding variables within vim are encoding,
fileencoding, and fileencodings. You can do
:help fileencoding
while within Vim to look at the documentation for each of these. As I
understand it, though, “encoding” is what Vim uses while you’re editing
the current file, “fileencoding” is the character set Vim thinks the
current file on disk is using (and what it will use to write the current
file to disk), and “fileencodings” is a list of encodings that Vim will
try when opening a file to guess which encoding is right. The default
seems to be
ucs-bom,utf-8,latin1
which means “look for a Unicode Byte-Order Marker to see if it looks
like UTF-16, otherwise see if it works as UTF-8, otherwise try Latin 1”.

So if you edit a Latin 1 file with Fedora Vim, you’re likely to see
[converted] messages on opening and saving, encoding will be utf-8 (so
you can type Unicode characters), and fileencoding will be latin1.

You can check each setting with
:set fileencoding
(or the appropriate variable), and set them with something like
:set fileencoding=latin1

Hope this helps,

James.

¹ The main exceptions are the Euro sign, and typographic punctuation
such as “proper” quotes. If you want to enter these easily in Vim, may I
recommend you look at UniCycle?
http://www.vim.org/scripts/script.php?script_id=1384

-- 
E-mail:     james@ | If infinite rednecks fired infinite shotguns at an
aprilcottage.co.uk | infinite number of road signs, they’d eventually
                   | create all the great literary works of the world.
                   | In braille.




More information about the fedora-list mailing list