118
votes

I work on webpages involving Non-English scripts from time to time, most of them uses utf-8 charset, VIM and Gvim does not display UTF-8 Characters correctly.

Using VIM 7.3.46 on windows 7 64 bit, with set guifont=Monaco:h10 in _vimrc

Is there a way to fix this?

Update: I've googled around and found set guifontwide acts as second fallback for regional languages.

I added the following lines in _vimrc and most of my problems got solved.

set enc=utf-8
set fileencoding=utf-8
set fileencodings=ucs-bom,utf8,prc
set guifont=Monaco:h11
set guifontwide=NSimsun:h12

The above NSimsun font works for Chinese, The problem is I don't know how they got the font name to work with VIM, Courier New is mentioned as Courier_New also NSimsun is nowhere in the font directory. The font I want to use is Latha But, I don't know how to use it in _vimrc File. set guifontwide=latha:h12 or set guifontwide=Latha:h12 doesn't work.

If I successfully set the guifontwide to latha, then my problem will be solved, How to do it?

9
what is the value of 'guifont' and the value of 'guifontwide'? Also, what OS are you using and what version of vim?Benoit
Sathish, were you able to find any solution for this? I'm trying to type in gVim with eKalappai software but vim is only showing me ?? characters (apparently saving them the same way).sundar - Remember Monica
@sundar No. I gave up :|Sathish Manohar
My problem was that inconsolata-g does not support the utf-8 characters in my document.AndrewPK
Using set guifontwide=NSimsun:h12 fails for me, says "Invalid wide font" probably the same non-monospace issue?mikew

9 Answers

66
votes

Did you try

:set encoding=utf-8
:set fileencoding=utf-8

?

66
votes

Try to reload the document using:

:e! ++enc=utf8

If that works you should maybe change the fileencodings settings in your .vimrc.

11
votes

If Japanese people come here, please add the following lines to your ~/.vimrc

set encoding=utf-8
set fileencodings=iso-2022-jp,euc-jp,sjis,utf-8
set fileformats=unix,dos,mac
6
votes

On Microsoft Windows, gvim wouldn't allow you to select non-monospaced fonts. Unfortunately Latha is a non-monospaced font.

There is a hack way to make it happen: Using FontForge (you can download Windows binary from http://www.geocities.jp/meir000/fontforge/) to edit the Latha.ttf and mark it as a monospaced font. Doing like this:

  1. Load fontforge, select latha.ttf.
  2. Menu: Element -> Font Info
  3. Select "OS/2" from left-hand list on Font Info dialog
  4. Select "Panose" tab
  5. Set Proportion = Monospaced
  6. Save new TTF version of this font, try it out!

Good luck!

4
votes

In Linux, Open the VIM configuration file

$ sudo -H gedit /etc/vim/vimrc

Added following lines:

set fileencodings=utf-8,ucs-bom,gb18030,gbk,gb2312,cp936
set termencoding=utf-8
set encoding=utf-8

Save and exit, and terminal command:

$ source /etc/vim/vimrc

At this time VIM will correctly display Chinese.

4
votes

this work for me and do not need change any config file

vim --cmd "set encoding=utf8" --cmd "set fileencoding=utf8" fileToOpen

2
votes

Is this problem solved meanwhile?

I had the problem that gvim didn't display all unicode characters (but only a subset, including the umlauts and accented characters), while :set guifont? was empty; see my question. After reading here, setting the guifont to a sensible value fixed it for me. However, I don't need characters beyond 2 bytes.

2
votes

I couldn't get any other fonts I installed to show up in my Windows GVim editor, so I just switched to Lucida Console which has at least somewhat better UTF-8 support. Add this to the end of your _vimrc:

" For making everything utf-8
set enc=utf-8
set guifont=Lucida_Console:h9:cANSI
set guifontwide=Lucida_Console:h12

Now I see at least some UTF-8 characters.

1
votes

On Windows gvim just select "Lucida Console" font.