在运行时快速切换字体


11

虽然可以从GVim菜单中手动选择字体,但我还是要根据手头的任务在一些首选字体之间进行切换(小位图,大OTF等)

有什么方法可以设置键绑定来循环浏览vimrc中预定义的字体列表?

Answers:


11

基本想法可能是这样的:

" 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

我的.vimrc文件中定义了以下内容。

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

因此,您可以将其设置为这样的映射...

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

为其他字体添加其他映射。

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.