Robert Hicks wrote:
Is there a function to determine if a font exists? Something like:

if exists("Monaco")
    set gfn=Monaco:h10
elsif exists("Consolas")
    set gfn=Consolas:h11
endif

Roughly...

Robert



Not exactly; but there are two possibilities to choose an existing font:

Method I.

Instead of setting 'guifont' to a single font, set it to a comma-separated list. The first one found will be set, or if none is found you'll get some "system default" monospace font.

Example for a cross-platform vimrc using Method I:

  if has('gui_running')
    if has('gui_gtk2')
      set gfn=Monaco\ 10,Consolas\ 11,B&H\ Lucidatypewriter\ 9
      set gfn+=Courier\ 10,Monospace\ 12
    elseif has('gui_kde')
      set gfn=Monaco/10/-1/5/50/0/0/0/1/0
      set gfn+=Consolas/11/-1/5/50/0/0/0/1/0
      set gfn+=B&H\ Lucidatypewriter/9/-1/5/50/0/0/0/1/0
      set gfn+=Courier/10/-1/5/50/0/0/0/1/0
      set gfn+=Monospace/12/-1/5/50/0/0/0/1/0
    elseif has('x11')
      set gfn=*-monaco-medium-r-normal-*-*-100-*-*-m-*-*
      set gfn+=*-consolas-medium-r-normal-*-*-110-*-*-m-*-*
      set gfn+=*-lucidatypewriter-medium-r-normal-*-*-90-*-*-m-*-*
      set gfn+=*-courier-medium-r-normal-*-*-100-*-*-m-*-*
      set gfn+=*-monospace-medium-r-normal-*-*-120-*-*-m-*-*
    else
      set gfn=Monaco:h10,Consolas:h11,Lucida_Console:h9
      set gfn+=Courier_New:h10,monospace:h12
    endif
  endif

Method II.

On some GUIs (including at least MS-Windows, GTK1, GTK2, Mac, Photon, and the obsolete kvim), you can use

        :set guifont=*

to pick your font from a menu (which will list only fonts available on your system and acceptable to your version of gvim). You will have to do it by hand though. Then after selecting a value,

        :set guifont=<Tab>

will (if 'nocompatible' is set) show the new value on the command-line, with escaping backslashes if and where needed: that's what you'll copy into your vimrc. Hit Esc to clear the command line -- or you can edit the value there and hit Enter to accept the changes, if you want to make a slight change to the current font setting.


Best regards,
Tony.

Reply via email to