Encoding problems...

1 view
Skip to first unread message

Andreas Rohrschneider

unread,
Dec 5, 2008, 11:23:50 AM12/5/08
to vim...@googlegroups.com

Hi all,

I am fiddling around with file encodings, which surely is quite complicated, and am currently stuck in the following problem:

First my settings:

encoding=utf-8
fileencodings=ucs-bom,utf-8,latin1
fileencoding=cp850

(fileencoding is set by an autocommand that decides by the file extension.)

In my vimrc I set a macro that inserts some kind of text, including umlauts. The encoding of my vimrc is latin1, which is
recognized correctly when I open it for editing. Therefore the encoding of the macro is latin1. I checked that by looking
at the map listing. There the macro is shown with the umlauts in <>-Notation (e.g. &auml; -> <e4>) which seems to be ok.

Anyway, when I use my map in the file mentioned above, the umlaut is inserted correctly, but the next two characters are missing.

This behavior is the same in vim 7.2.60 and 6.4.4. Everything works just fine, when I change 'encoding' to latin1 though...

Am I doing something wrong? Is there a bug?



Thanx a lot in advance,
   Andreas

Tony Mechelynck

unread,
Dec 5, 2008, 7:14:41 PM12/5/08
to vim...@googlegroups.com

I think Vim doesn't know, when running the vimrc, that it's running code
written in Latin1 even after you switch 'encoding' to UTF-8.

I suggest adding the following line just after the point where you
switch to UTF-8, or at the top of your vimrc if you don't (and your
encoding=utf8 is purely due to your OS locale):

scriptencoding latin1

This command tells Vim that the current script, until its end or until
another ":scriptencoding" command (whichever comes first) is written in
Latin1 encoding.

In general, mappings may become invalid when 'encoding' is changed, so
you should not define any mappings before you set the 'encoding' you
will be using until the end of the session. (Once 'encoding' is set to
UTF-8, you ought to be able to edit any file without changing it again.)
If you are currently defining the mappings first, and setting 'encoding'
afterwards, then you should move the mappings to after setting
'encoding' to UTF-8 (and ":scriptencoding" to Latin1).

Alternately, write your vimrc in UTF-8, make sure that everything in it
before you set 'encoding' to UTF-8 uses only bytes lower than 0x80, and
write your umlaut-mappings in UTF-8, after you set 'encoding'. In that
case, you may use ":scriptencoding utf-8" after setting 'encoding' but I
am not sure it is necessary. What I am sure of is that it doesn't hurt.


See also
:help :scriptencoding
http://vim.wikia.org/wiki/Working_with_Unicode


Best regards,
Tony.
--
To a Real Woman, every ejaculation is premature.

Reply all
Reply to author
Forward
0 new messages