6

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.

だから、私は次のことをしたいと思います:

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

問題は、それがうまくいかないことです... CentOS6.3 と Debian Whey で数時間試してみましたが、このコマンドをこのように書くと、VIM は Sans フォントで始まります。私は何か間違ったことをしていますか?システム上にあるフォントをどのようにスマートに検出しますか?

4

3 に答える 3

5

OK、これはおそらく正しい方法ではないことはわかっていますが、うまくいきます。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

このスニペットは、がインストールされているかどうかDroid Sans Mono、および がインストールされているかどうかを確認しInconsolataます。最初のものがインストールされている場合、UI フォントは になりDroid Sans Mono、そうでない場合は に設定されInconsolata、最後に に設定されMonospaceます。Windows 7 では、カンマ区切りのリストが機能します。

于 2013-03-29T15:13:50.277 に答える