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 2 at 12:29
  • 2
    Fwiw, I have a simple and more flexible version here: github.com/benknoble/Dotfiles/blob/… – D. Ben Knoble Jul 2 at 12:36
  • It's the GTK version. I will update the post. – Erik Lievaart Jul 2 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 2 at 12:53
  • 1
    It just gives me a more elegant way to create the same problem ;) – Erik Lievaart Jul 2 at 13:12
3

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.

| improve this answer | |

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.