vim 手册指出:
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.
Run Code Online (Sandbox Code Playgroud)
所以,我想做以下事情:
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
Run Code Online (Sandbox Code Playgroud)
问题是它对我不起作用......我已经在 CentOS6.3 和 Debian Wheey 上尝试了几个小时,但是当我像这样写这个命令时,VIM 只会从 Sans 字体开始。难道我做错了什么?您如何巧妙地检测系统上的字体?
好吧,我知道这可能不是正确的方法,但它确实有效。所以,这是我为 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
Run Code Online (Sandbox Code Playgroud)
此代码片段将检查是否Droid Sans Mono已安装,以及是否Inconsolata已安装。如果第一个安装,则 UI 字体将为Droid Sans Mono,如果不是,则设置为Inconsolata,最后设置为Monospace。在 Windows 7 上,逗号分隔列表可以正常工作。