1

I wanted an easy way to resize the font in gvim (GTK), so I found this post:

Quickly switch between fonts at runtime

I created the following bindings based on that post:

    let g:fc_list = [ 
    \   "Inconsolata Semi-Condensed 11",
    \   "Inconsolata Semi-Condensed 12",
    \   "Inconsolata Semi-Condensed 13",
    \   "Inconsolata Semi-Condensed 14",
    \   "Inconsolata Semi-Condensed 15",
    \   "Inconsolata Semi-Condensed 16",
    \   ]   
    let g:fc_current = 3 
    let &guifont = g:fc_list[g:fc_current]
function! FontCycle(increment)
    let g:fc_current = (g:fc_current + a:increment) % len(g:fc_list)
    let &guifont = g:fc_list[g:fc_current]
    redraw
endfunction

noremap ;- :call FontCycle(-1)<CR>
noremap ;= :call FontCycle(1)<CR>
noremap ;p :set guifont?<CR>

The bindings work great, but when the font size decreases white bars remain on the bottom and right of the screen. I tried redraw and clear, but neither worked. In case it's relevant: I use i3wm.

white bars

Does anyone know how to have the editor render properly, after changing the font size?

  • 1
    I suppose you are using the GTK gui version? Have a look at :h gtk-css – Christian Brabandt Jul 02 '20 at 12:29
  • 2
    Fwiw, I have a simple and more flexible version here: https://github.com/benknoble/Dotfiles/blob/8ce03b978db7311f00f03525396acf8579f99ef1/links/vim/gvimrc#L8 – D. Ben Knoble Jul 02 '20 at 12:36
  • It's the GTK version. I will update the post. – Erik Lievaart Jul 02 '20 at 12:52
  • I will be using D. Ben Knoble's version from here on out, since it's more elegant. It doesn't change the issue though. – Erik Lievaart Jul 02 '20 at 12:53
  • @ErikLievaart If that fixes your problem don't hesitate to answer your own question to help future users reading it :) – statox Jul 02 '20 at 12:54
  • 1
    It just gives me a more elegant way to create the same problem ;) – Erik Lievaart Jul 02 '20 at 13:12
  • Welcome to [vi.se]! Since it's a visual problem, consider attaching a screenshot or similar to display the issue. Christian's comment was pointing out that GTK gvim will use a CSS file that you can possibly tweak, so maybe changing something in there such as a color attribute would be able to solve your problem... Did you take a look at the help section he pointed out? – filbranden Jul 02 '20 at 13:47
  • Ah, thanks for clarifying. I read the comment and the section, but I had no idea what he meant to say. I added a screenshot and will play around with the css for a little bit. – Erik Lievaart Jul 02 '20 at 14:20
  • What happens if you do a :set columns=999? – Ralf Jul 02 '20 at 17:30
  • It fixes the columns! and with set lines=999 I can almost fix the rows. It leaves just a couple of empty rows at the end, but it's workable like this. @Ralf you should turn your solution into an answer so that I can credit you with the solution. – Erik Lievaart Jul 03 '20 at 12:22

1 Answers1

4

First: I have no experience with i3wm. So my observation from "normal" windows manager.

Vim is working with monospaced fonts. So every character is displayed in a box with a certain width and height in pixels. If you change the size of the font, the size of this box changes.

If the GVim window is not fullscreen, the size of the window will change with the change of font size. The width in characters is still the same, but as the width & height of the single characters change, the window size have to be changed.

Different in fullscreen. Now Vim will adjust the number of columns according to the font size. Smaller -> more columns & lines. Bigger -> less columns/lines.

The problem is, that the fullscreen window has a fixed width in pixels and the characters have a fixed width in pixels. If the canvas1 width modulo the the character box width is not zero, there will be a white bar at the right.

Simple example: Width of canvas is 1000 pixel, width of characters is 13 pixel. With that you can display 76 characters per line, but you have 12 pixels left. So you get a 12 pixel bar on the right.

The same for a bar at the bottom.

1: By "canvas" i mean the part of the window, that Vim uses for text. So window width minus border, minus scrollbar, minus ... .


Assumptions for i3wm:

Vim doesn't know that it is in a fullscreen-like environment. By "fullscreen-like" I mean an environment, where the window size is not adjusted to the content, as i3wm defines the window size as fixed (for the application).

So when changing the font size you should always add these commands:

set columns=999
set lines=999
redraw!

With this Vim will always display as much columns and lines as possible.

It is still likely, that there is some small unused area to the left and bottom (see above). From my understanding this should be less than one char wide/high.

Ralf
  • 9,197
  • 1
  • 11
  • 30