95

How do I set the default font for MacVim?

I have tried adding the following line

set guifont = Monaco:h12

to either of the following files:

~/.vimrc
~/.gvimrc
~/Applications/MacVim/MacVim.app/Contents/Resources/vim/vimrc
~/Applications/MacVim/MacVim.app/Contents/Resources/vim/gvimrc
~/Applications/MacVim/MacVim.app/Contents/Resources/vim/.vimrc
~/Applications/MacVim/MacVim.app/Contents/Resources/vim/.gvimrc

I restarted MacVim, but it still won't set the default font. Anything I missed?

UPDATE: I can issue the set guifont command in runtime and it works fine. It just doesn't seem to read it off my startup files.

Kit
  • 30,365
  • 39
  • 105
  • 149
  • I use a font different from the default with the above command in `~/.vimrc` and it works perfectly fine. Perhaps you might want to check if the particular font exists... – abcd Dec 13 '11 at 01:47
  • @yoda I actually tried doing `set guifont=Monaco:h12` during runtime and it works fine. I'm not sure why it doesn't read it off the startup files I mentioned. – Kit Dec 13 '11 at 01:58
  • You may use `vim -D` to enter [debug mode](http://vimdoc.sourceforge.net/htmldoc/repeat.html#debug-scripts) and then `step` through vim startup scripts to see what is going on. – user688996 Dec 13 '11 at 02:19
  • 5
    @kit: The code in your post has spaces before and after the equals sign in your `set guifont` statement. If it's really that way in your vimrc then take the spaces out, they're not valid around equals sign in set statements (actually I think a space before the equals is okay, but not after). – Herbert Sitz Dec 13 '11 at 04:16

6 Answers6

142

Place this in .gvimrc:

set guifont=Monaco:h12

Note the lack of spaces around the equals sign.

Kit
  • 30,365
  • 39
  • 105
  • 149
98

If you need to set a font with spaces in the name, use backslashes in your .gvimrc:

set guifont=Fira\ Code:h12
New Alexandria
  • 6,951
  • 4
  • 57
  • 77
28

The most complete answer should be this:

set guifont=Source\ Code\ Pro\ ExtraLight:h18

I looked around and each answer and tutorial I found didn't specify how to set the typeface.

After setting your font manually using the Font window, if you are unsure exactly what to put type:

:set guifont

This will show you the exact string value you need to put in your .vimrc file, including the typeface.

Benjamin
  • 1,832
  • 1
  • 17
  • 27
8

Attach my fonts setting.

" - font type and size setting.
if has('win32')
    set guifont=Consolas:h12   " Win32.
elseif has('gui_macvim')
    set guifont=Monaco:h14     " OSX.
else
    set guifont=Monospace\ 12  " Linux.
endif
Chu-Siang Lai
  • 2,658
  • 1
  • 24
  • 21
4

To deal with not just English characters, you can put this in your .vimrc file (guifontwide deals with Chinese characters):

if has("gui_running")
    set guifont=Consolas:h14
    set guifontwide=Hiragino\ Sans\ GB
    set linespace=2
endif
Hustlion
  • 2,203
  • 1
  • 19
  • 22
  • I'm guessing `wide` means each character is encoded by more than 8 bits, hence it's wide? Or does it actually appear wide? – Kit Apr 07 '17 at 05:52
3

If you're on Mac, add these lines to your ~/.vimrc:

set gfn=Monaco:h13
set linespace=2
Farshid Ashouri
  • 16,143
  • 7
  • 52
  • 66