How to easily test for guifont in vimrc?

vim

Solution

Not a direct solution to your problem, but you could use `hostname()` and a conditional statement to select the font you would like:

  if hostname() == 'home-pc'
      set guifont=...
  elseif hostname() == 'work-pc'
      set guifont=...
  else
      set guifont=...
  endif

Problem

I have many different machines that I am logging into and none of them have decent fonts in common. So, I would like to be able to have my first preferance for a font but if it does not exist on the machine use another one and so on. Has anyone done this before? ... So after re-reading the help on guifont it seems that I should be able to have multiple fonts defined seperated by commas. The funny thing is though I have the following line in my .vimrc: ``` set guifont=-dt-interface\ user-medium-r-normal-*-*-100-*-*-m-*-iso8859-1,Liberation\ Mono\ 8 ``` And on one machine (gvim 7.1) I do a ``` :set gfn? guifont=-dt-interface user-medium-r-normal-*-*-100-*-*-m-*-iso8859-1 ``` And on another machine (gvim 7.2) I get: ``` :set gfn? guifont=-dt-interface user-medium-r-normal-*-*-100-*-*-m-*-iso8859-1,Liberation Mono 8 ``` I will try to run 7.1 on the incorrect machine and see if it fixes the problem and if so doesn't it seem like a bug in 7.2? SOLUTION Here is the code I cam up with to fix the problem. It seems very brittle but it at least allows me to make some progress with my real work for now: ``` " SETTINGS FOR GUI ONLY MODE : Trying to emulate how it should work but on some machines it will not select the available font " set guifont=-dt-interface\ user-medium-r-normal-*-*-100-*-*-m-*-iso8859-1,Liberation\ Mono\ 8 let g:MyFontPre = '' let g:MyFontPost = '' let g:MyFontSize = '8' if has("gui_running") if ( match(hostname(), 'server5-1..') >= 0 ) let g:MyFontSize = '10' let g:MyFontPre = '-dt-interface\ user-medium-r-normal-*-*-' let g:MyFontPost = '0-*-*-m-*-iso8859-1' elseif ( match(hostname(), 'server5-3..') >= 0 ) let g:MyFontPre = 'Liberation\ Mono\ ' let g:MyFontPost = '' else " Leave it the default for now endif execute "set guifont=".g:MyFontPre."".g:MyFontSize."".g:MyFontPost endif " FONT SIZE SHORTCUTS function! ToggleMyFontSize() if ( g:MyFontSize == 12 ) let g:MyFontSize = 8 execute "set guifont=".g:MyFontPre."".g:MyFontSize."".g:MyFontPost elseif ( g:MyFontSize == 8 ) let g:MyFontSize = 10 execute "set guifont=".g:MyFontPre."".g:MyFontSize."".g:MyFontPost elseif ( g:MyFontSize == 10 ) let g:MyFontSize = 12 execute "set guifont=".g:MyFontPre."".g:MyFontSize."".g:MyFontPost endif endfunction nnoremap <silent> <F12> :call ToggleMyFontSize()<CR> ```

Original source