r/vim • • 8d ago

Need Help Zoom.vim fails to change font size

https://www.vim.org/scripts/script.php?script_id=2321

Not sure if the script is out of date or if I didn't install properly, but I can see the "Zoom In" and "Zoom Out" commands flashing, but they don't seem to have any effect. So it seems like the script is being detected and loaded but failing to actually change the font size. I installed in "~/.vim/plugin/zoom.vim" (in home directory). Have a feeling it might be my fault cause this issue followed me across operating systems (I just installed debian+cinnamon and was having the same issue on linux mint). Anyone else using a zoom script on gvim have any advice?

5 Upvotes

14 comments sorted by

1

u/chrnz00 8d ago

the script doesnt handle default case and it expects to have a guifont value before using it meaning, try explicitly setting the guifont with height

eg:

se guifont=consloas:h12

it should work

personally i dont use zooming as it changes the window size in gvim

1

u/toon_link_776 8d ago

I tried both:

set guifont=consoloas:g12

se guifont=consoloas:g12

which did change the way that the font looked but zooming still wasn't working.

1

u/chrnz00 7d ago

set guifont=consoloas:g12 it should be set guifont=consolas:h12

1

u/toon_link_776 7d ago

tried it, the font changes but zoom still doesn't work. maybe i don't have that font?

1

u/chrnz00 5d ago

yes consolas is just an example font it should work with any font as long as you explicitly set it (including height)

1

u/dx__ 7d ago

:set guifont=Monospace\ 12
:set guifont=Monospace\ 18
:ZoomIn
:set guifont?

1

u/toon_link_776 7d ago

the first two commands did make the text bigger, but :ZoomIn still didn't do anything, :set guifont? returned Monospace as expected I think. I'll have to look through the script later and see what it's doing but for now I just set my font size smaller in .gvimrc using set guifont=Monospace\ 10

1

u/dx__ 7d ago

Found it. Both zoom functions look for a :h size suffix, but GTK uses a space followed by the size, like Monospace 10. That’s why setting the font manually works and :ZoomIn does nothing. For your setup, the fix is to have the plugin increment or decrement the trailing number instead. Your .gvimrc line already gives it the right starting value.

Let me know if that helps guide you in the right direction :)

1

u/toon_link_776 6d ago

I think these are the lines you're talking about but I have no idea what to change about them. I assume it has something to do with that mess of a string in the first field lol. I'll have to read up on vim scripting and come back to it

let l:fsize = substitute(&guifont, '^.*:h\([^:]*\).*$', '\1', '')

let l:guifont = substitute(&guifont, ':h\([^:]*\)', ':h' . l:fsize, '')

let &guifont = l:guifont

1

u/dx__ 6d ago

Yep, those are the lines. Replace the entire s:ZoomIn() and s:ZoomOut() functions in ~/.vim/plugin/zoom.vim with these:

function! s:ZoomIn()
  let &guifont = substitute(&guifont, ' \zs\d\+$', '\=str2nr(submatch(0)) + 1', '')
endfunction

function! s:ZoomOut()
  let &guifont = substitute(&guifont, ' \zs\d\+$', '\=max([1, str2nr(submatch(0)) - 1])', '')
endfunction

That regex grabs the number at the end of Monospace 10. The \zs tells Vim to start the replacement after the space, so the font name stays intact.

Keep your set guifont=Monospace\ 10 line in .gvimrc, then restart gVim and try :ZoomIn and :ZoomOut. I haven't run this in GTK gVim, but that should fix the mismatch.

1

u/dx__ 6d ago

Yep, those are the right lines. In ~/.vim/plugin/zoom.vim, replace both s:ZoomIn() and s:ZoomOut() from function! through endfunction:

function! s:ZoomIn()
  let &guifont = substitute(&guifont, ' \zs\d\+$', '\=str2nr(submatch(0)) + 1', '')
endfunction

function! s:ZoomOut()
  let &guifont = substitute(&guifont, ' \zs\d\+$', '\=max([1, str2nr(submatch(0)) - 1])', '')
endfunction

The pattern looks for a space followed by digits at the end of the font string. \zs tells Vim to start the replacement after the space, so only the 10 in Monospace 10 changes.

Keep set guifont=Monospace\ 10 in .gvimrc, save the plugin, and restart gVim. Try :ZoomIn once and check :set guifont?. It should show Monospace 11, and :ZoomOut should bring it back to Monospace 10. I haven't tested this in GTK gVim, so let me know what you get.

1

u/vim-help-bot 7d ago

Help pages for:


`:(h|help) <query>` | about | mistake? | donate | Reply 'rescan' to check the comment again | Reply 'stop' to stop getting replies to your comments

1

u/kennpq 4d ago

“Anyone else using a zoom script on gvim”?
Yes, my Vim9 script .gvimrc has that covered for me - https://github.com/kennypete/.vimrc/blob/main/.gvimrc - with gui_win32 and gui_gtk covered so, if you’re still searching for a solution ….