My &guifont is set using let &guifont="SauceCodePro NF 11,Source code pro 11".

Calling set guifont? returns the full option, guifont=SauceCodePro NF 11,Source code pro 11.

Is there a way to check which of the two fonts gvim eventually used, if any?

Reading :h guifont didn't give me any ideas.


If there really isn't a simple query to find the information then we'll have to brute-force it...

Two key behaviors are described in :h 'guifonts':

[If a list of fonts is given] the first valid font is used.


[If a single font is given and] the font cannot be found you will get an error message.

That suggests something like this function:

func! ReportFirstValidGuiFont()
    " preserve existing value
    let l:fonts = &guifont

    for font in split(l:fonts, ",") 
            exe "set guifont=" . font
            echo "Applied GUI font: " . font
        catch /E596/
            " ie: Vim(set):E596: Invalid font(s): guifont=<font-name>
            echo v:exception
            " always restore original value
            let &guifont = l:fonts

Call with :call ReportFirstValidGuiFont() and it will iterate over the comma separated font list, setting each font as the sole guifonts value. It will print a message naming the first one that doesn't cause an error and exit. The printed name should be the font that is currently applied.

  • Is the return a bug? – D. Ben Knoble Nov 24 '19 at 14:34
  • @D.BenKnoble How so? All we care about is the first font that doesn't cause an error. So if we get past the set guifont line we print and bail. – B Layer Nov 25 '19 at 4:43
  • Yeah misread my bad – D. Ben Knoble Nov 25 '19 at 12:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.