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.
I ran into the same issue. The problem here is that when Vim calls gui_init_font
(code) it expects if gui_mch_get_font
(code) fails it can move on to the next font in the comma-separated list. But in GTK gui_mch_get_font
calls pango_font_description_from_string
(code) which will never fail, it'll just return a default.
But pango_font_description_from_string
itself takes a comma-separated list of families followed by style options, size and variations and has its own fallback logic (doc) withe the following format: [FAMILY-LIST] [STYLE-OPTIONS] [SIZE] [VARIATIONS]
. Thus escape your list as follows:
if has("gui_running")
if has("gui_gtk2") || has("gui_gtk3")
set guifont=Droid\ Sans\ Mono\\,Inconsolata\\,Monospace 10
elseif has("gui_win32")
set guifont=Droid\ Sans\ Mono:h10,Consolas:h11:cANSI
endif
endif
Then Pango will do the fallback work and pick the right font for you. On GTK it seems to be best to fully escape your string and let GTK do the logic.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With