Comment on PEP 263 - Defining Python Source Code Encodings

Martin v. Löwis loewis at informatik.hu-berlin.de
Sun May 12 13:12:30 EDT 2002


Robin Becker <robin at jessikat.fsnet.co.uk> writes:

> I already knew that in fact it seems to be the encoding flag that
> determines things. I think fileencoding is used for possible conversion
> of the file into the required encoding. Thus both 
> gvim --cmd="set encoding=utf8" aaaa.txt
> gvim --cmd="set encoding=utf8" aaaa.txt

Did you mean to use fileencoding in one of these lines?

> display a utf8 file, aaaa.txt, correctly, but the latter has actually
> converted the characters to latin1 (at least for me).

'encoding' specifies the encoding used internally in vim. This
normally doesn't matter (vim could use whatever it wants to); except
that vim also assumes the encoding of the terminal is equal to the
internal encoding.

What matters is the fileencoding. When opening a file, it converts it
from the fileencoding to the internal encoding. Hence, in a Latin-1
terminal, setting encoding to utf8 is not helpful. Instead, setting
fileencoding is more useful.

The most useful setting (in a .vimrc) is fileencodings, which is a
list of encodings tried in sequence. If this list is 'utf8,latin1',
vim will first check whether the file is UTF-8; if it isn't, it will
fall-back to Latin-1. The value of fileencoding is then inferred from
this guessed value.

Still, if you put 'fileencoding=' *inside* the file, it won't work, in
any released version of vim. That's a bug though, and hopefully fixed
some day.

Regards,
Martin



More information about the Python-list mailing list