vhakulinen / gnvim

GUI for neovim, without any web bloat
MIT License
1.84k stars 69 forks source link

Add configuration script examples? #210

Closed linuxtim closed 7 months ago

linuxtim commented 1 year ago

I've decided to try gnvim because nvim-qt scrolling performance was poor for me (QT5 / Debian 12 / Wayland).

I think it would be useful to include some example gnvim configuration scripts, and mention these in the README.md.

The only config that I was missing from nvim-qt was using Ctrl + the mouse scrollwheel to change the font size. I implemented the following and would be happy to create a PR for this, if you let me know where you think such config snippets and examples should live in the source tree?


-- FIXME reinstate the following line after
-- https://github.com/vhakulinen/gnvim/issues/208 is closed.
--if vim.g.gnvim ~= nil then
if true then
        -- You can use tools such as Gnome font-manager to browse fonts
        -- (select from Categories -> Spacing -> Monospace).

        -- Initial Font without size info

        -- Default Monospace font
        --local font_name = "Mono"

        -- Commissioned by Google, SIL Open Font/Apache License
        local font_name = "Noto Mono"
        --local font_name = "Noto Mono Bold"

        -- Terminus Open Type Bitmap, SIL Open Font/Apache License
        -- Bitmap font, for sharp text at small point sizes, particularly on low dpi
        -- displays - https://terminus-font.sourceforge.net/
        --local font_name = "Terminus"

        -- Default font size
        local font_size = 16

        -- Arbitrary Min and Max size limits for adjusting font size
        local font_size_min = 6
        local font_size_max = 40

        -- gtk font selections look like e.g. "Terminus 20"
        local set_font = function(name, size)
                vim.opt.guifont = name .. " " .. size
        end

        set_font(font_name, font_size)

        local adjust_font_size = function(delta)
                font_size = font_size + delta
                if font_size < font_size_min then
                        font_size = font_size_min
                end
                if font_size > font_size_max then
                        font_size = font_size_max
                end
                set_font(font_name, font_size)
        end

        adjust_font_size(0)

        -- Map Ctrl-Scroll up/down to change font size
        vim.keymap.set({"i", "n"}, "<C-ScrollWheelUp>", function() adjust_font_size(1) end)
        vim.keymap.set({"i", "n"}, "<C-ScrollWheelDown>", function() adjust_font_size(-1) end)
end
vhakulinen commented 1 year ago

I don't mind such examples being in the readme if they are kept brief enough (e.g. keep only one of the mentioned fonts). They can later be moved elsewhere if deemed necessary.

FWIW, I've been meaning of adding font resize functionality directly into gnvim, since it can do so without any additional parsing and/or book keeping of the font name and size.