Skip to content

Instantly share code, notes, and snippets.

@slimane
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save slimane/9822549 to your computer and use it in GitHub Desktop.
Save slimane/9822549 to your computer and use it in GitHub Desktop.
command! -nargs=0 -bar FontReSize call s:changeFontSize()
function! s:changeFontSize()
let font_size_pat = '(.{-}\S:h)(\d+\.?\d*)(.{-})'
let valid_num_pat = '\d+(\.(0|5))?'
let current_font_size = substitute(&guifont, '\v^' . font_size_pat . '$', '\2', '')
if current_font_size !~ '\v^' . valid_num_pat . '$'
return
endif
" disalbe ime
let default_im_insert = &iminsert
let &iminsert = 0
let default_im_disable = &imdisable
let &imdisable = 1
while 1
let l:input = input("\press esc to exit\n", '')
if l:input =~ '\v^(\+|-)$'
let new_font_size = string(eval(current_font_size) + (l:input == '+' ? +0.5 : -0.5))
elseif l:input =~ '\v^(\+|-)' . valid_num_pat . '$'
let new_font_size = string(eval(current_font_size) + eval(l:input))
elseif l:input =~ '\v^' . valid_num_pat . '$'
let new_font_size = l:input
elseif l:input == ''
break
else
echo "\nInvalid Input"
continue
endif
if eval(new_font_size) > 0.5 && new_font_size =~ '\v^' . valid_num_pat . '$'
let &guifont = substitute(&guifont, '\v(^|,)' . font_size_pat . '(,|$)', '\2' . new_font_size . '\4', 'g')
let &guifontwide = substitute(&guifontwide, '\v(^|,)' . font_size_pat . '(,|$)', '\2' . new_font_size . '\4', 'g')
let current_font_size = new_font_size
redraw
endif
endwhile
let &iminsert = default_im_insert
let &imdisable = default_im_disable
endfunction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment