The vim manual states:
On systems where 'guifontset' is supported (X11) and 'guifontset' is
not empty, then 'guifont' is not used.
Spaces after a comma are ignored. To include a comma in a font name
precede it with a backslash. Setting an option requires an extra
backslash before a space and a backslash. See also
|option-backslash|. For example: >
:set guifont=Screen15,\ 7x13,font\\,with\\,commas
will make Vim try to use the font "Screen15" first, and if it fails it
will try to use "7x13" and then "font,with,commas" instead.
So, I would like to do the following:
if has("gui_running")
if has("gui_gtk2")
set guifont=Droid\ Sans\ Mono,Inconsolata,Monospace
elseif has("gui_win32")
set guifont=Droid\ Sans\ Mono:h10,Consolas:h11:cANSI
endif
endif
Trouble is that it does not work for me... I have been trying for a couple of hours on CentOS6.3 and Debian Wheey, but when ever I write this command like this, VIM will just start with Sans font. Am I doing something wrong? How do you smartly detect which fonts are on the system ?
OK, I know this is probably not the right way, but it works. So, here is how I set a fallback font for VIM-GTK:
if has("gui_running")
if has("gui_gtk2")
let dsm=system('fc-list | grep -c Droid\ Sans\ Mono')
let cons=system('fc-list | grep -c Inconsola')
if ( dsm > 0)
set gfn=Droid\ Sans\ Mono\ 10
elseif ( cons > 0)
set gfn=Inconsolata\ 12
else
set gfn=Monospace\ 10
endif
elseif has("gui_win32")
set guifont=Droid\ Sans\ Mono:h10,Consolas:h11:cANSI
endif
endif
This snippet will check if Droid Sans Mono
is installed, and also if Inconsolata
is installed.
If the first one is install, the UI font will be Droid Sans Mono
, if not it will be set to Inconsolata
, and finally, it will be set to Monospace
.
On Windows 7 the comma separated list just works.