Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Resize gvim window when the font changes

Tags:

vim

I have a laptop attached to a 1440p screen. Depending on which screen I'm using, I find myself adjusting gvim's font size often. When I do, the number of lines in the window remains the same. I'm also using a tiling window manager, so gvim is always running in a window of a fixed size. The result of this is that increasing the font pushes the status line out of the visible window and decreasing the font leaves me with dead space.

The workaround I've found so far is to open and close a terminal. Resizing gvim forces it to recalculate how much space window it has to draw in. Is there a way to trigger that effect without spawning another window?

like image 550
valadil Avatar asked Sep 08 '25 18:09

valadil


2 Answers

I figure out a few workarounds:

  • set guioptions+=k: not exactly what we need, but this tells Vim that the window size is not going to change when the font size changes (which is what happens here anyway so no problem).
  • set lines=999 columns=9999: according to Vim documentation, this will set it to the maximum value possible (although it doesn't really work for me, the number of lines/columns is computed based on the whole screen size instead of just the window part)
  • set go+=m go-=m: this seems to force vim to recompute 'lines'. Unfortunately the analog set go+=r go-=r doesn't make it recompute 'columns'...
  • although set go+=r go-=r does make vim recompute 'columns' when go-k is set. So a full workaround, if you don't want set guioptions+=k, is set go+=k go+=mr go-=mr go-=k (or something similar).
like image 123
user202729 Avatar answered Sep 10 '25 07:09

user202729


Ok, I have a stupid hack that works around the problem. I'm not going to accept my own answer here because this is a question about gvim, but in case anyone else bumps into this thread before it gets a legit answer, here's my hack.

  silent !xterm -e sleep .1;exit

I just dumped that in my font resizing command, which is bound to + and -.

like image 32
valadil Avatar answered Sep 10 '25 08:09

valadil