set gvim font in .vimrc file

Yongwei Xing picture Yongwei Xing · Jul 23, 2010 · Viewed 169.9k times · Source

I am using gVim 7.2 on Windows 7. I can set the gui font as Consolas 10 (font size) from the menu. I am trying to set this in .vimrc file like below:

set guifont=Consolas\ 10

But it doesn't work. Does anyone know how to set this?

Answer

Morten Siebuhr picture Morten Siebuhr · Jul 23, 2010

I use the following (Uses Consolas size 11 on Windows, Menlo Regular size 14 on Mac OS X and Inconsolata size 12 everywhere else):

if has("gui_running")
  if has("gui_gtk2")
    set guifont=Inconsolata\ 12
  elseif has("gui_macvim")
    set guifont=Menlo\ Regular:h14
  elseif has("gui_win32")
    set guifont=Consolas:h11:cANSI
  endif
endif

Edit: And while you're at it, you could take a look at Coding Horror's Programming Fonts blog post.

Edit²: Added MacVim.