Created
April 13, 2012 12:13
-
-
Save yamaya/2376542 to your computer and use it in GitHub Desktop.
MacVimでCommand+[+-]でフォントサイズを変える
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" guifontオプションは"フォント名:hフォント高"の形式で設定しておく必要がある | |
function! ResizeFontGetGuiFontOption() | |
let matches = matchlist(&guifont, '\(.*\):h\(\d\+\)\(:.*\)\?') | |
if empty(matches) && matches[2] == '' | |
return {} | |
endif | |
return {'name': matches[1], 'size': matches[2], 'opts': matches[3]} | |
endfunction | |
function! ResizeFontBy(amount) | |
let font = ResizeFontGetGuiFontOption() | |
if empty(font) | |
return | |
endif | |
if !exists('s:gvimrc_initial_font') | |
let s:gvimrc_initial_font = deepcopy(font) | |
endif | |
let font.size += a:amount | |
if font.size < 9 || font.size > 30 | |
return | |
endif | |
let &guifont = font.name.':h'.font.size.font.opts | |
endfunction | |
function! ResizeFontReset() | |
if exists('s:gvimrc_initial_font') | |
echomsg string(s:gvimrc_initial_font) | |
let font = ResizeFontGetGuiFontOption() | |
if empty(font) | |
return | |
endif | |
let &guifont = font.name.':h'.s:gvimrc_initial_font.size.s:gvimrc_initial_font.opts | |
endif | |
endfunction | |
nnoremap <expr><D-+> ResizeFontBy(1) | |
nnoremap <expr><D-=> ResizeFontBy(-1) | |
nnoremap <expr><D-0> ResizeFontReset() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment