I'm running gVim 7.3 on a GNU/Linux machine. I'm wondering if there is a way to change the font automatically based on the size of the window. I'm relatively new to Vim, so I'm not terrible familiar with it.
My situation is this: I'm using DejaVu Sans Mono 12 for my default font, but sometimes I like to switch down to Terminus 9 when I want to shrink the Vim window down to look at something on my screen while I type. (You know, for those of us with tiny laptop screens that don't want to keep switching between workspaces...!)
So I'm wondering if this behaviour can happen automatically with a command in the .vimrc file if I shrink the default window size down small enough so that Vim will automatically adjust the font.
Any ideas?
Vim fires the VimResized
event when its window size is changed. You can write an autocmd that adapts the font ('guifont'
) then. Here's an example that only considers 'columns'
(not 'lines'
), and has a hard-coded font name:
function! FontChangeOnResize()
if &columns > 80
set guifont=Lucida_Console:h14
elseif &columns > 60
set guifont=Lucida_Console:h12
elseif &columns > 40
set guifont=Lucida_Console:h10
elseif &columns > 20
set guifont=Lucida_Console:h8
else
set guifont=Lucida_Console:h6
endif
endfunction
autocmd VimResized * call FontChangeOnResize()
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