111

I am trying to configure the default settings for my GUI with Vim. I already made research on the web, but all the solutions I found and tried did not work.

Here are some of the things I tried (in the .vimrc file):

set guifont = Monaco:h20
set guifont=Monospace 20

Actually I don't care about the Monaco font.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Moebius
  • 6,242
  • 7
  • 42
  • 54
  • The first one looks correct. Did you restart vim? Also, does the font exist on your machine? – Rob Jul 07 '13 at 02:06
  • 4
    Vim comes with a *very* extensive documentation. Don't search the web: use `:help` instead; it's faster and more authoritative. In your case, a simple `:help font` would have been enough for you to find `:help guifont` and learn how to `set guifont` correctly for your system. – romainl Jul 07 '13 at 08:26

8 Answers8

233

For the first one remove the spaces. Whitespace matters for the set command.

set guifont=Monaco:h20

For the second one it should be (the h specifies the height)

set guifont=Monospace:h20

My recommendation for setting the font is to do (if your version supports it)

set guifont=*

This will pop up a menu that allows you to select the font. After selecting the font, type

set guifont?

To show what the current guifont is set to. After that copy that line into your vimrc or gvimrc. If there are spaces in the font add a \ to escape the space.

set guifont=Monospace\ 20
Venkataraman R
  • 12,181
  • 2
  • 31
  • 58
FDinoff
  • 30,689
  • 5
  • 75
  • 96
  • I tried the following command in my .vimrc : set guifont=h18 || set guifont=Monospace:h18 || set guifont=18 and if some of them make the police bigger, there is a prblem : the space between each characters is very wide. Why ? – Moebius Jul 07 '13 at 10:23
  • I just understood that the wide space between character is due to the font which is non mono. Just fonts with the mono inside its name will be displayed without wide space. – Moebius Jul 07 '13 at 11:10
  • Where to find vimrc? I did'nt find it in start menu after installing vim on win8.1 – Lei Yang May 04 '16 at 08:24
  • 1
    @LeiYang If you type `:version` in vim it should list the locations where vim looks for the file. It should be something like `~/.vimrc`, `~/.vim/vimrc`, `$HOME/_vimrc`. – FDinoff May 04 '16 at 14:35
  • I feel silly asking this, but does this work on vim on terminal (ie. not gvim)? – 0xc0de May 15 '17 at 07:12
  • @0xc0de This does not work on terminal. The terminal controls the font (and it is generally in its preferences.) – FDinoff May 15 '17 at 20:04
  • Yes, that's what I use, the gnome-terminal settings. I wish to have different font sizes in different splits, so was curios about this, unfortunately I seem to be too optimistic about it. – 0xc0de May 16 '17 at 05:56
  • I can't get this to work on Windows10 / gvim. set guifont=* works and opens a font selector windows, but typing `set guifont?` or adding it to the configuation file does nothing – 576i Aug 24 '17 at 12:10
  • Note that you need to type `:set guifont?` to get it to work. Adding `=*` is not necessary, just select the desired font from the menu first. – 576i Aug 24 '17 at 12:22
  • Mine (in ~/.vimrc) : `set guifont=Monaco\ 11` thank you. – SdSaati Jun 16 '18 at 16:53
18

Try a \<Space> before 12, like so:

:set guifont=Monospace\ 12
oxfist
  • 749
  • 6
  • 22
pascal
  • 181
  • 1
  • 4
2

I cross over the same problem I put the following code in the folder ~/.gvimrc and it works.

set guifont=Monaco:h20
Chandler B
  • 111
  • 7
0

Add Regular to syntax and use gfn:

set gfn= Monospace\ Regular:h13

Farshid Ashouri
  • 16,143
  • 7
  • 52
  • 66
0

The other answers are what you asked about, but in case it’s useful to anyone else, here’s how to set the font conditionally from the screen DPI (Windows only):

set guifont=default
if has('windows')
    "get dpi, strip out utf-16 garbage and new lines
    "system() converts 0x00 to 0x01 for 'platform independence'
    "should return something like 'PixelsPerXLogicalInch=192'
    "get the part from the = to the end of the line (eg '=192') and strip
    "the first character
    "and convert to a number
    let dpi = str2nr(strpart(matchstr(substitute(
        \system('wmic desktopmonitor get PixelsPerXLogicalInch /value'),
        \'\%x01\|\%x0a\|\%x0a\|\%xff\|\%xfe', '', 'g'),
        \'=.*$'), 1))
    if dpi > 100
        set guifont=high_dpi_font
    endif
endif
9999years
  • 1,561
  • 13
  • 14
0

You may find useful this plugin I made to simplify setting guifont in a portable way: https://github.com/awvalenti/vim-simple-guifont. Your vimrc goes like this and it handles all the OS specific stuff:

silent! call simple_guifont#Set(
  ['Cascadia Code PL', 'JetBrains Mono', 'Hack'], 'Consolas', 14)
André Willik Valenti
  • 1,702
  • 14
  • 21
-1

set guifont=Lucida\ Console:h10

-1

In Ubuntu 22, for gvim, setting the "Ubuntu Mono" font with size 11 will be this in .vimrc:

set guifont=Ubuntu\ Mono\ 11

SobiX
  • 11
  • 1
  • 3
  • Don't at least two of the existing answers cover this syntax? Please don't add duplicate answers, and please don't add "thank you" as an answer. – ChrisGPT was on strike Jul 14 '22 at 22:49
  • The previous answers were either with "h:" or the font name was not in two parts. None of them even though they guided me to the answer, but they didn't work on my system. Therefore, my answer was to combine the previous ones for Ubuntu and in the case of a font with a name of more than one section. – SobiX Jul 16 '22 at 06:19