22

I wanted to add a UTF-8 font in Gvim but I could not find out how to do this. I tried to follow the step on this manual but it still did not work. http://www.inter-locale.com/whitepaper/learn/learn_to_type.html (vim section halfway the page)

Can anyone tell me how to add a font in Vim so I can have Japanese characters displayed ?

djs
  • 4,626
  • 2
  • 28
  • 38
user18383
  • 551
  • 3
  • 8
  • 12
  • You don't specify what OS you using for gvim, so do you mean adding a font to your operating system so it's available for gvim, or do you mean using a font that's already correctly installed? – m0j0 Oct 30 '08 at 21:45

5 Answers5

21

As others note, you must use a fixed-width font. Vim is a text editor, not a WYSIWYG editor.

If you have a fixed-width font with the characters you need then:

:set guifont=*

Select the font you want to use, the size, etc. Once you're happy with it, do:

:set guifont?

And it will output the current setting of the value. Put the set guifont=foo in your .gvimrc (or in .vimrc with a if has("gui_running") block).

set guifont=<C-R>=&guifont<CR>

That will put the current value into the file.

muru
  • 4,723
  • 1
  • 34
  • 78
Zathrus
  • 9,948
  • 2
  • 25
  • 22
  • Do NOT use quotes. took me some time to figure this out. `set guifont=Consolas:h14:cANSI` – gcb Oct 03 '12 at 22:51
  • 3
    > *Vim is a text editor, not a WYSIWYG editor.* I don't understand how that's relevant here, how is a variable-width font any more "WYSIWYG" than a fixed-width one? – Sundar R Oct 02 '13 at 15:45
20

For Windows, I found using the guifontwide setting provided the expected functionality (i.e. mixed character display: Japanese, Chinese and English in the same file). This is not intuitive or obvious (at least not to me!) from the Vim help files, but having something like this in your startup settings will work:

set guifont=Consolas:h10 
set guifontwide=MingLiU:h10 "For windows to display mixed character sets
set encoding=utf-8 
atomicules
  • 2,155
  • 25
  • 24
  • 1
    This is exactly the right answer. I checked the documentation and it's quite obscure even after the fact. When I had this set to nothing, characters just showed up as empty spaces, not even rectangles. – djs Jan 07 '13 at 03:35
  • This made my Chinese chars show... but failed to show my Hebrew chars. The answer from @ThomasJ (set only guifont=MingLiU:h10) seems to work – xverges Nov 18 '13 at 16:02
5

Quote from the vim documentation:

For MS-Windows, some fonts have a limited number of Unicode characters. Try using the "Courier New" font. You can use the Edit/Select Font... menu to select and try out the fonts available. Only fixed-width fonts can be used though. Example:
        :set guifont=courier_new:h12

So, I guess, unless you find a fixed width font containing the characters you want to display, then you are out of luck.

HS.
  • 2,593
  • 2
  • 20
  • 28
3

This is what I use...

set gfn=MingLiU:h16:cDEFAULT
set fenc=utf-8
set encoding=utf-8

Put this in your _vimrc file, exit and reopen. Works like a charm for me. +T

xverges
  • 4,608
  • 1
  • 39
  • 60
ThomasJ
  • 31
  • 1
2

You have to use a fixed-width font for Gvim under Windows.

There are several relevant pages at the Vim Tips Wiki:

George V. Reilly
  • 15,885
  • 7
  • 43
  • 38