11

While fonts can be manually selected in GVim from the menu, I have a few preferred fonts I would like to switch between depending on the task at hand (small bitmap, larger OTF... etc).

Is there a way I can setup key-binding to cycle over a list of fonts predefined in my vimrc?

12

The basic idea could be something like:

" Define a list of the fonts you want to use, and the index in the 
" list of the default font. See :help Lists
let g:fc_list = [
\   "DejaVu Sans Mono 9",
\   "Source Code Pro 12",
\   "GohuFont 11"
\   ]
let g:fc_current = 0

" Set default font
let &guifont = g:fc_list[g:fc_current]

function! FontCycle()
  " Increment circular list. See :help expr-%
  let g:fc_current = (g:fc_current + 1) % len(g:fc_list)
  let &guifont = g:fc_list[g:fc_current]
endfunction

noremap <leader>fc :call FontCycle()<cr>
7

I have the following defined in my .vimrc file.

set guifont=DejaVu\ Sans\ Mono\ for\ Powerline\ 10

So you can set that up as a mapping like this...

nmap <Leader>f :set guifont=DejaVu\ Sans\ Mono\ for\ Powerline\ 10<CR>

Add additional mappings for other fonts.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.