Vim: How to handle Unicode files with text in multiple (more than two) languages?

9

2

What settings do I need to set in Vim/gVim to be able to view Unicode text files which have text in many languages?

You may make these assumptions:

  • The number of languages is more than two.
  • Some of the languages are Chinese, Japanese, and Korean.
  • It is enough if I can view these files in gVim (not necessarily Vim).
  • gVim 7.0 running on Windows.

Here is a text sample, which when saved in Unicode opens fine in Notepad, but shows up as gibberish in gVim:

This is English.
这是中文。
これは日本です。
한국입니다.
ಇದು ಕನ್ನಡ.

Ashwin Nanjappa

Posted 2009-07-22T03:07:48.593

Reputation: 8 705

Jerryjvl: There seems to be Unicode support in GViM. I have not been successful in enabling it to work with >2 languages. http://www.vim.org/htmldoc/mbyte.html

– Ashwin Nanjappa – 2009-07-22T03:20:03.857

3Your example works just fine when pasted into gvim on Linux. Suggest upgrading OS :-D – derobert – 2009-07-22T04:38:55.597

Answers

7

Using gVim on Windows, I did the following two things:

:set encoding=utf-8
:set guifont=*

The second command brings up a font picker. By choosing the font "@MS Mincho", I got some of the Japanese characters to display, but oddly they were rotated 90 degrees to the left.

Anyway, you'll have to set the encoding before loading or pasting text into gVim (otherwise it might just convert them to all question marks). Then you'll have to find a font that is (a) fixed width, and (b) includes the characters you want to see. I don't seem to have such a font on my system at the moment, but you may.

Greg Hewgill

Posted 2009-07-22T03:07:48.593

Reputation: 5 099

the same is true for any os: you need vim to use the right encoding AND the right font to display the glyphs of the font. so, mark greg's answer 'accepted' :) – akira – 2009-09-22T05:13:38.617

Thanks Greg! So by setting the encoding as UTF-8 we enable GViM to make sense of the bytes it is reading, but sadly it cannot display all those languages using a single fixed-width font, hence gibberish is displayed. – Ashwin Nanjappa – 2009-12-05T07:23:36.463

0

Using the following settings in your .vimrc
:set encoding=utf-8
:set guifont=*
:set guifontwide=*

may work for you. It worked for me for chinese/japanese characters.

GuruM

Posted 2009-07-22T03:07:48.593

Reputation: 291

You can also try the following:
:set fileencoding=utf-8 :set fileencodings=ucs-bom,utf-8,latin1 :set *encoding=utf-8
– GuruM – 2012-08-07T11:05:10.503

0

The font Arial Unicode MS supports japanese, chinese and korean as well as vietnamese and arabic. You could try using that font, though I don't believe it is monospaced.

http://www.microsoft.com/typography/fonts/font.aspx?FMID=1081

There may be other pan-language fonts out there, perhaps monospaced ones as well, but I don't know of them.

edit

I found this page with a few fonts that support all three languages. Some of them are available as free downloads: http://www.wazu.jp/gallery/Fonts_Japanese.html

meskarune

Posted 2009-07-22T03:07:48.593

Reputation: 336