5

I find that when I type Chinese characters (encoded with UTF-8) into VIM, I cannot see them at all while they do exist there. I can copy and paste them into other text editors and it seems everything is fine. How can I fix this problem?

I say Reinstate Monica
  • 25,487
  • 19
  • 95
  • 131
SpawnST
  • 2,351
  • 5
  • 27
  • 38

2 Answers2

4

you are not using a font which contains the glyphs needed to display the characters you typed.

so, choose the right font via

:set guifont=*

or

:set guifontwide=*

which would pop up a font-selection-dialog. and once you have a working font make it permanent by putting

set guifont=YOURFONT

to your .gvimrc / .vimrc

akira
  • 61,009
  • 17
  • 135
  • 165
  • Neither of these worked for me on Debian with `VIM - Vi IMproved 7.3 (2010 Aug 15, compiled Feb 10 2013 02:28:47)`. No font-selection-dialog appeared. – Mike Oct 08 '13 at 01:51
  • @Mike: `guifont` settings are for `gvim`. are you using console-vim? if so: consult the manual of your terminal-program (which is responsible for drawing glyphs). – akira Oct 08 '13 at 04:54
  • Ahh, didn't notice that little detail. – Mike Oct 08 '13 at 06:02
4

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.

  • Could you explain about the line `set fileencoding=utf-8,ucs-bom,gb18030,gbk,gb2312,cp936`? – Niing Apr 21 '21 at 12:54
  • @Niing a bit late to the party, but I found and explanation here (last part of the document): https://titanwolf.org/Network/Articles/Article?AID=a4d8c31e-438c-4a8e-9ff1-75fe324acaf1#gsc.tab=0 – Bruno Belotti Aug 11 '21 at 01:19