[windows] set gvim font in .vimrc file

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?

This question is related to windows vim

The answer is


Try setting your font from the menu and then typing

:set guifont?

This should display to you the string that Vim has set this option to. You'll need to escape any spaces.


When I try:

set guifont=Consolas:h16

I get: Warning: Font "Consolas" reports bad fixed pitch metrics

and the following is work, and don't show the waring.

autocmd vimenter * GuiFont! Consolas:h16

by the way, if you want to use the mouse wheel to control the font-size, then you can add:

function! AdjustFontSize(amount)
    let s:font_size = s:font_size + a:amount
    :execute "GuiFont! Consolas:h" . s:font_size
endfunction

noremap <C-ScrollWheelUp> :call AdjustFontSize(1)<CR>
noremap <C-ScrollWheelDown> :call AdjustFontSize(-1)<CR>

and if you want to pick the font, you can set

set guifont=*

will bring up a font requester, where you can pick the font you want.

enter image description here


Ubuntu 14.04 LTS

:/$ cd etc/vim/
:/etc/vim$ sudo gvim gvimrc

After if - endif block, type

set guifont=Neep\ 10

save the file (:wq!). Here "Neep" (your choice) is the font style and "10" is respect size of the font. Then build the font - cache again.

:/etc/vim$ fc-cache -f -v

Your desired font will set to gvim.


I had to end up doing

:set guifont=Courier:h10:cANSI

For Windows do the following:

  1. Note down the font name and font size from the "Edit-Select Font..." menu of "gvim.exec".
  2. Then do :e $MYGVIMRC
  3. Search for "guifont" string and change it to set guifont=<font name as noted>:h<font size>
  4. Save the file and quit.
  5. Next time when you execute gvim.exec, you will see the effect.

  1. Start a graphical vim session.
  2. Do :e $MYGVIMRC Enter
  3. Use the graphical font selection dialog to select a font.
  4. Type :set guifont= Tab Enter.
  5. Type G o to start a new line at the end of the file.
  6. Type Ctrl+R followed by :.

The command in step 6 will insert the contents of the : special register which contains the last ex-mode command used. Here that will be the command from step 4, which has the properly formatted font name thanks to the tab completion of the value previously set using the GUI dialog.


Although this is an old thread I thought that I would add a comment as I have come across it whilst trying to solve a similar issue; this might help anyone else who may find themselves here:

The backslash character is used to ignore the next character; once added to the font name in my gvimrc it worked; I am on a GNU/Linux machine which does not like spaces. I suspect that the initial post was an error due to the back slash being used on a windows machine.

In example:

:set guifont?  ## From gvim command, would give the following:

set guifont=DejaVu Sans Mono for Powerline 11

Where as I needed to add this line to the gvimrc file for it to be read:

set guifont=DejaVu\ Sans\ Mono\ for\ Powerline\ 11

I am trying to set this in .vimrc file like below

For GUI specific settings use the .gvimrc instead of .vimrc, which on Windows is either $HOME\_gvimrc or $VIM\_gvimrc.

Check the :help .gvimrc for details. In essence, on start-up VIM reads the .vimrc. After that, if GUI is activated, it also reads the .gvimrc. IOW, all VIM general settings should be kept in .vimrc, all GUI specific things in .gvimrc. (But if you do no use console VIM then you can simply forget about the .vimrc.)

set guifont=Consolas\ 10

The syntax is wrong. After :set guifont=* you can always check the proper syntax for the font using :set guifont?. VIM Windows syntax is :set guifont=Consolas:h10. I do not see precise specification for that, though it is mentioned in the :help win32-faq.