How to view UTF-8 Characters in VIM or Gvim

Vim

Vim Problem Overview


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?

Vim Solutions


Solution 1 - Vim

Did you try

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

?

Solution 2 - Vim

Try to reload the document using:

:e! ++enc=utf8

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

Solution 3 - Vim

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

Solution 4 - Vim

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!

Solution 5 - Vim

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.

Solution 6 - Vim

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

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

Solution 7 - Vim

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.

Solution 8 - Vim

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.

Solution 9 - Vim

On Windows gvim just select "Lucida Console" font.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionSathish ManoharView Question on Stackoverflow
Solution 1 - VimMaxim SloykoView Answer on Stackoverflow
Solution 2 - VimBenoitView Answer on Stackoverflow
Solution 3 - VimkujiyView Answer on Stackoverflow
Solution 4 - VimYi ZhaoView Answer on Stackoverflow
Solution 5 - VimJohn Paul Qiang ChenView Answer on Stackoverflow
Solution 6 - Vimuser2204107View Answer on Stackoverflow
Solution 7 - VimTobiasView Answer on Stackoverflow
Solution 8 - VimRyan ShillingtonView Answer on Stackoverflow
Solution 9 - VimAlex DvoretskiyView Answer on Stackoverflow