Sunday, October 3, 2010

How to set utf-8 locally (for a buffer) on loading the file

I need a way to set utf-8 encoding only for a particular file, on
opening it.

I'm using gvim 7.3 on Windows. I have the following situation
regarding locale and languages:

1) The OS language is English
2) The Windows LANG environment variable is set to DE (because I live
in Germany).
3) The gvim 'installation language' is German. With this I mean that
the menus are in German.
4) My vim locale is English (that is, my _vimrc contains 'lang
english')

These settings are fine for most purposes. However, I also have a
special file in which I'm collecting text lines in Japanese. The text
in the file is not maintained manually but is being written to by
another application.

A little trial and error shows that, when making the following
settings *after* the file has been opened for reading, the Japanese
text is correctly displayed:

set encoding=utf-8
set guifont:MS_Mincho:h10:cSHIFTJIS

However, this has the undesirable collateral effect that it does not
only affect the buffer with this particular Japanese text but all open
and future buffers.

I tried 'fileencoding', which didn't work. From the documentation I
kind of understand that 'fileencoding' only affects user input after
the variable was set, which in my case is useless. I don't care user
input, I just want the text to show in the correct encoding (utf-8).
The 'on opening' part can be achieved with an autocommand (I used to
use a modeline until 7.2, but setting encoding from a modeline seems
to be forbidden from 7.3).

Does anybody know how to handle this?
Thank you
e.


--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

No comments: