tags:

views:

745

answers:

2

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>
+1  A: 

Try this and this

Thomas Geritzma
These are basic commands on setting the guifont. I know how to do that. What I want to know is there an automated way to check that a font exists on the machine I am currently running on.
stephenmm
There isn't a way to do it script-amatically. You could use some font previewer, but that's another story alltogether. I suggest the approach from the first link, just put several fonts, and you're bound to hit one of them.
Thomas Geritzma
+3  A: 

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
too much php