Help, Vim doesn't render thai character in my os, but the Notepad does.

478 views
Skip to first unread message

Nwngz

unread,
Oct 12, 2007, 2:21:59 PM10/12/07
to vim_use
I'm a newbie on lovely vim.
I've saved/set the file with UTF-8 encoding, but it doesn't work! But
the notepad of Windows XP handle it correctly, other editor like
EditPlus, Wordpad (from windows) also work well. Is this a bug? Or I
made some mistake on the setting? Can anyone help me out?

Thai alphabet

middle class consonants 9

(k) (j) (d) (t) (d)
(t) (b) (p) (o)


high class consonants 10

(kh) (ch) (th) (th) (ph)
(f) (s) (s) (s) (h)

low class consonants 23


(kh) (kh) (ng) (ch) (s)
(ch) (y) (th) (th) (n)
(th) (th) (n) (ph) (f)
(ph) (m) (y) (r) (l)
(y) (l) (h)

Nwngz

unread,
Oct 12, 2007, 2:26:37 PM10/12/07
to vim_use
It's seems the thai character can't be posted. I've uploaded a file
named "Thai alphabet utf.txt", please check it out.

Tim Chase

unread,
Oct 12, 2007, 2:33:46 PM10/12/07
to vim...@googlegroups.com
> I'm a newbie on lovely vim.
> I've saved/set the file with UTF-8 encoding, but it doesn't work!

I'm guessing that it's merely a configuration issue.

Are you running vim or gvim? If you're running (console) vim,
your console may not be able to display the characters even if
vim tells it to.

However, if you are running gvim (or vim in a console that
supports UTF-8), then it's likely a configuration issue.

It would help if you included the output of

:set fenc? enc? tenc? fencs? bomb?

to see more about what your settings include.

-tim

Tony Mechelynck

unread,
Oct 12, 2007, 2:34:22 PM10/12/07
to vim...@googlegroups.com

see http://vim.wikia.com/wiki/Working_with_Unicode

Once 'encoding' is set to UTF-8 and 'fileencodings' to the proper value (such
as with ":set fencs=ucs-bom,utf-8,GB18030,latin1"), if just ":e filename"
doesn't recognise the encoding you may try ":e ++enc=utf-8 filename" or (if
saved as "Windows unicode") ":e ++enc=utf-16le filename" (see ":help ++opt").


Best regards,
Tony.
--
"I refuse to have a battle of wits with an unarmed person."

Tony Mechelynck

unread,
Oct 12, 2007, 2:46:45 PM10/12/07
to vim...@googlegroups.com
Nwngz wrote:
> It's seems the thai character can't be posted. I've uploaded a file
> named "Thai alphabet utf.txt", please check it out.

Could you give us a full URL?


Best regards,
Tony.
--
Psychiatrists say that one out of four people are mentally ill. Check
three friends. If they're OK, you're it.

Nwngz

unread,
Oct 12, 2007, 3:23:18 PM10/12/07
to vim_use
Thanks all!

I edit the file with gVim from Windows XP (pathed to SP2).

I'm sorry for missing the file URL, you can find it here:
http://groups.google.com/group/vim_use/files.

Also, I've uploaded a screenshot for it,

And, after the file loaded,
encoding = cp936
termencoding =
fileencodings = ucs-bom,utf-8,chinese,taiwan,japan,korea,latin1
bomb? = bomb

here is the setting to fileencodings from my vimrc:

" encodings
set fileencodings=ucs-bom,utf-8,chinese,taiwan,japan,korea,latin1

Nwngz

unread,
Oct 12, 2007, 3:26:09 PM10/12/07
to vim_use
The screen shot was named to "thai_char_error.PNG". In that
screenshot, all the thai alphabet are render as "?". :-(

Tony Mechelynck

unread,
Oct 12, 2007, 3:55:03 PM10/12/07
to vim...@googlegroups.com

You should not edit a UTF-8 file with 'encoding' set to cp936, because many
characters can be represented in UTF-8 but not in cp936.

See in my other reply the URL of a vim-wiki article about how to use Unicode
in Vim.


Best regards,
Tony.
--
hundred-and-one symptoms of being an internet addict:
51. You put a pillow case over your laptop so your lover doesn't see it while
you are pretending to catch your breath.

Szabolcs

unread,
Oct 12, 2007, 4:26:04 PM10/12/07
to vim_use

On Oct 12, 8:21 pm, Nwngz <anonymouslys...@gmail.com> wrote:
> I'm a newbie on lovely vim.
> I've saved/set the file with UTF-8 encoding, but it doesn't work! But
> the notepad of Windows XP handle it correctly, other editor like
> EditPlus, Wordpad (from windows) also work well. Is this a bug? Or I
> made some mistake on the setting? Can anyone help me out?

I can confirm that Vim 7.1.138 on WinXP does not show the Thai
characters in this file (only boxes appear), even though the font
settings are the same as for Notepad (which works correctly).

However, the Windows CharMap.exe program tells me that none of the
fixed width fonts have Thai characters on my system. So I guess that
Notepad is actually falling back to some other (non-fixed-width) font
when it displays Thai characters.

Nwngz

unread,
Oct 12, 2007, 4:54:24 PM10/12/07
to vim_use
> You should not edit a UTF-8 file with 'encoding' set to cp936, because many
> characters can be represented in UTF-8 but not in cp936.

Thanks.

I've set the encoding to utf-8, and re-open the file, but all the Thai
characters are drawing as box (not "?" this time).

I found your reply to the thead "How to edit UTF-8 files with gVim on
WinXP when "encoding=cp1250" ?", and take all the steps that you
wrote, but the problem sitll there.

I guess that gVim can't display the Thai characters with other writing
characters in the windows without specific font.

But why Notepad can handle it correctly, even its font settings same
as gVim. The only answer that I can guess out, is that, Notepad (it is
only a Edit control with a few file operating) drawing all the
character with the Microsoft Uniscribe Unicode script processor engine
to handle complex writing characters, but gVim doesn't.

Tony Mechelynck

unread,
Oct 12, 2007, 4:56:24 PM10/12/07
to vim...@googlegroups.com

On Linux, I can see the Thai glyphs in SeaMonkey or in gvim; but I'm using the
GTK2 GUI, which will fall back on a different font, even a variable-width one
(and clip it at the character cell if too wide or space-fill it if too narrow)
if the current 'guifont' hasn't got the right glyph. SeaMonkey for Linux (or,
I should say, Gecko for Linux) also uses GTK2.

My 'guifont' is set by:

:set gfn=Bitstream\ Vera\ Sans\ Mono\ 9

which is how 9-point "Bitstream Vera Sans Mono" must be set for the GTK2
version of gvim. No other version accepts this format (for Windows, if you had
that font, you would say ":set gfn=Bitstream_Vera_Sans_Mono:h9"). However,
some Thai glyphs are slightly clipped in gvim. They "marry" well with the
other Bitstream Vera Sans Mono glyphs, however, so either they've been
"borrowed" from some very similar font, ot this font is not strictly "mono" in
Thai.

Your (Nwngz's) file,
http://vim_use.googlegroups.com/web/Thai%20alphabet%20utf.txt , is a UTF-8
text file with B.O.M. I don't expect it to be displayable in cp936.


Best regards,
Tony.
--
OUTCONERR
Twas FORTRAN as the doloop goes
Did logzerneg the ifthen block
All kludgy were the function flows
And subroutines adhoc.

Beware the runtime-bug my friend
squrooneg, the false goto
Beware the infiniteloop
And shun the inprectoo.

Tony Mechelynck

unread,
Oct 12, 2007, 5:16:48 PM10/12/07
to vim...@googlegroups.com

Try

:set guifont=*

to get a fonts menu in gvim. Try pasting some Thai text in the "example" box
in the menu, to see if (and how) the Thai characters display in that font.
Then try all the fonts you have installed, until either you find one that
works, or you come to the end of the list.

If you don't have a working monospace font for Thai, check the Windows Update
site for a Thai language pack.


The code for your vimrc should be something similar to

if &enc !~? '^u' " if not already Unicode
if &tenc == "" " avoid clobbering the keyboard encoding
let &tenc = &enc
endif
set enc=utf-8
endif
" the following are the file-encodings we want to detect:
" ucs-bom (if used) should be first;
" at most one 8-bit encoding (such as latin1) should be used, and
" it must be last;
" when opening a file, Vim will use the leftmost entry which produces
" no conversion error.
set fencs=ucs-bom,utf-8,GB18030,shift-jis,euc-jp,euc-kr,latin1
" GB18030 is the latest Mainland Chinese encoding standard
" shift-jis and euc-jp are Japanese
" euc-kr is a Korean encoding.

" the following two are optional
setglobal bomb " to write new Unicode files with BOM by default
setglobal fenc=GB18030 " default encoding for new files


Best regards,
Tony.
--
Under a government which imprisons any unjustly, the true place for a
just man is also in prison.
-- Henry David Thoreau

Nwngz

unread,
Oct 13, 2007, 6:27:07 AM10/13/07
to vim_use
Thank you.

I have that "Bitstream Vera sans mono" installed, and have set guifont
to that face, but also have the problem. Even I've change the default
encoding to UTF-8 or convert my "thai alphabet utf.txt" to "plain"
utf-8 file (withou BOM).

gVim was able to handle the Thai syllable but unable to display it
correctly, it render the Thai syllable as a "?" or just a box, is that
mean gVim treat the glyphs of Thai characters/sylleble as "glyphs that
outside the current font"?

I haven't installed any Thai language pack or font, but my IE /
Opera / Firefox / Notepad / EditPlus are all rendering correctly! So,
I have a question: Does the Vim (gVim) able to work well with a file
that contain Thai character or any others writing characters that
doesn't belong to current language of the OS, with the correct
rendering, under the Windows?

Yongwei Wu

unread,
Oct 13, 2007, 6:57:22 AM10/13/07
to vim...@googlegroups.com

You've got a problem here. The font chosen on my Windows XP box is
Angsana New, which is NOT a fixed-width font. Vim requires the use of
fixed-width fonts. You need to find a suitable fixed-width font on
the Internet yourself to use with Vim.

Best regards,

Yongwei

--
Wu Yongwei
URL: http://wyw.dcweb.cn/

Nwngz

unread,
Oct 13, 2007, 7:40:55 AM10/13/07
to vim_use
---------------------- Chinese reply begin ---------------------

吴兄,问题是,我尝试了所有的字体,却始终不能正确显示泰文,而小小的记事本却可以正确显示,甚至任何 Windows 中适用的 Edit 输入框都
能显示,而且字体设置跟 gVim 中的设置是完全相同的,都是"新宋体"。我百思不得其解!莫非 gVim 用的字符描绘功能是自己写的,而不是
Windows 自带的那些?

或者这是 gVim 的天生限制,不能同屏显示多国文字。不过这应该不太可能吧!?

---------------------- Chinese reply end ---------------------

Have you got my "Thai alphabet utf.txt" rendering correct? From the
gVim font selector dialog, it just list all the fixed-width fonts that
resides in my Simplified Chinese Windows XP SP2, and I've try them
all!

May I have your suggestion on a "suitable font" that gVim can work
well?

Yongwei Wu

unread,
Oct 13, 2007, 10:07:47 AM10/13/07
to vim...@googlegroups.com
On 13/10/2007, Nwngz <anonymo...@gmail.com> wrote:

I know you have tried the available fonts on Windows. I tried it
myself. That was why I said "you've got a problem" instead of "you
should try such and such". :-)

Did you notice that the character width is different from the Western
characters in Notepad? Notepad is supposed to use fixed-width fonts,
but it seems it can resort to variable-width fonts when necessary.


Vim requires the use of fixed-width fonts.

Forget about SimSun: it is not the true font used. E.g., you can
apply Courier New on Chinese characters, and Chinese characters still
display correctly (at least on Chinese Windows). Courier New never
contains Chinese characters.

As to the detailed ways that the fonts are rendered, I do not have
ideas. It probably has something to do with the fact that Vim needs
to have fixed-width characters. In Notepad, or in the text input
boxes in the browser, the width of Thai characters is apparently
different from other characters.

Windows has more than one set of controls/APIs to render the
characters. I believe only some have the characteristics that you
described.

I was about to suggest your setting your Windows locale to Thai, but I
found that there was no such setting. I mean, I did not find Thai in
Control Panel > Regional and Language Options > Advanced > Language
for non-Unicode programs on my Windows XP box. That seems to imply
that Windows XP does not have proper support for Thai in the version I
use (and probably your version too).

I googled for "fixed width thai font", and it seems chances are that
you can find some on the net. I believe they are your solution and
should work.

---- Chinese summary ----
就像前面我说过、别人也说过的那样,Windows上没有等宽字体支持泰文。因为
在我的XP上,我无法把缺省语言切成泰文,我怀疑在中文/英文版本的Windows中
本来就是不能完整支持泰文的。不提供等宽字体就是证据。要么Bram修改Vim支
持变宽字体,要么你找到支持泰文的等宽字体(见上一段英文),要么放弃使用
Vim。
---- Chinese summary ----

Tony Mechelynck

unread,
Oct 13, 2007, 11:18:04 AM10/13/07
to vim...@googlegroups.com
Nwngz wrote:
> Thank you.
>
> I have that "Bitstream Vera sans mono" installed, and have set guifont
> to that face, but also have the problem. Even I've change the default
> encoding to UTF-8 or convert my "thai alphabet utf.txt" to "plain"
> utf-8 file (withou BOM).
>
> gVim was able to handle the Thai syllable but unable to display it
> correctly, it render the Thai syllable as a "?" or just a box, is that
> mean gVim treat the glyphs of Thai characters/sylleble as "glyphs that
> outside the current font"?

- In Vim 7.0 or earlier, or in 7.1 builds without patch 116 (see the output of
":version"), all Unicode codepoints above U+FFFF are shown as a question mark
(which may be double-width, for "wide" CJK characters). They can be edited
correctly, but not displayed.

- In any version, characters not available in the current 'encoding' (e.g.
Thai characters when 'encoding' is set to cp936) may be represented by a
question mark. WARNING: In this configuration, writing the file back to disk
will lose some data, because Vim is unable to represent the offending
characters in memory.

- Un Unicode (i.e., with 'encoding' set to "utf-8"), the customary glyph for a
character not in the font is a black diamond with a white question mark on it.

- In other encodings, chareacters not in the font (but defined in the current
'encoding') may be displayed variously; often as a hollow box or as a blank space.

>
> I haven't installed any Thai language pack or font, but my IE /
> Opera / Firefox / Notepad / EditPlus are all rendering correctly! So,
> I have a question: Does the Vim (gVim) able to work well with a file
> that contain Thai character or any others writing characters that
> doesn't belong to current language of the OS, with the correct
> rendering, under the Windows?

Unlike gvim (other than GTK2 versions which are not for Windows), the IE,
Opera and Firefox browsers can use variable-width fonts. (I don't know about
Notepad.) To display _any_ text in gvim, you must set 'guifont' to some
installed _fixed-width_ font containing the necessary glyphs for your text.


Best regards,
Tony.
--
Keep grandma off the streets -- legalize bingo.

Nwngz

unread,
Oct 13, 2007, 1:50:09 PM10/13/07
to vim_use
Thank you so much!

Now I got all the idea. I've downloaded some fixed-width Thai fonts,
and set the encoding properly and gVim displayed correct characters
now!

Although gVim work well, but it did more complicated operations to
take the correct result than other unicode editors, some chars
rendering are not so pretty enough. I have to increase the font size
bigger than two times chinese font. So I think I sould use other
unicode editor to edit a file that contain Thai.

Thnaks again. Enjoy and have a good day.

----------- Chinese reply ------------

谢谢吴兄的解答。

----------- Chinese reply ------------

Tony Mechelynck

unread,
Oct 13, 2007, 7:36:09 PM10/13/07
to vim...@googlegroups.com
Nwngz wrote:
> Thank you so much!
>
> Now I got all the idea. I've downloaded some fixed-width Thai fonts,
> and set the encoding properly and gVim displayed correct characters
> now!
>
> Although gVim work well, but it did more complicated operations to
> take the correct result than other unicode editors, some chars
> rendering are not so pretty enough. I have to increase the font size
> bigger than two times chinese font. So I think I sould use other
> unicode editor to edit a file that contain Thai.

...unless you can find some "prettier" monospace Thai font. Now that you've
done it once, the second time will be *much* easier.

>
> Thnaks again. Enjoy and have a good day.

My pleasure, and you too.

>
> ----------- Chinese reply ------------
>
> 谢谢吴兄的解答。

Sorry, wo3 bu2 zuo4 zhong1 wen2. (IIRC)

>
> ----------- Chinese reply ------------

Best regards,
Tony.
--
Remember, drive defensively! And of course, the best defense is a good
offense!

Reply all
Reply to author
Forward
0 new messages