11

I want to zoom in VIM, like Sublime text or Atom, using CTRL + & CTRL - and CTRL 0 for reset to default font-size.

11

If you are using vim in a terminal you can simply use its zoom shortcuts. For Gnome-Terminal this is Ctrl++. In others it may be Ctrl+Shift++.

Also there are several plugins out there for this purpose. e.x: https://github.com/drmikehenry/vim-fontsize

As an alternative you can define your own functions like this one from vim.wika.com

let s:pattern = '^\(.* \)\([1-9][0-9]*\)$'
let s:minfontsize = 6
let s:maxfontsize = 16
function! AdjustFontSize(amount)
  if has("gui_gtk2") && has("gui_running")
    let fontname = substitute(&guifont, s:pattern, '\1', '')
    let cursize = substitute(&guifont, s:pattern, '\2', '')
    let newsize = cursize + a:amount
    if (newsize >= s:minfontsize) && (newsize <= s:maxfontsize)
      let newfont = fontname . newsize
      let &guifont = newfont
    endif
  else
    echoerr "You need to run the GTK2 version of Vim to use this function."
  endif
endfunction

function! LargerFont()
  call AdjustFontSize(1)
endfunction
command! LargerFont call LargerFont()

function! SmallerFont()
  call AdjustFontSize(-1)
endfunction
command! SmallerFont call SmallerFont()

An then map two keys to :LargerFont and :SmallerFont

2

Apparat's answer works for gVim; if you're using Vim from within a Terminal, you will need to configure the terminal to change the font size.

For Xterm, I like to use:

XTerm*VT100.translations: #override \n\
    Ctrl <KeyPress> =:larger-vt-font() \n\
    Ctrl <KeyPress> -:smaller-vt-font()

In my ~/.Xdefaults to change the font size with CTRL + and CTRL -.

Some terminals also respond to escape codes to set the font; for Xterm I've never been able to get that to work correctly, though...

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.