changing global variable value neovim

I am trying to define a custom lua configuration for the nvim-qt GUI. In order to do so, I would first like to toggle fullscreen on and off, but I encounter some pretty weird behavior.

vim.g.nvim_qt = {
    fullscreen = false,
    fontsize = 14,
    font_name = 'Iosevka\\ NF:h'

local toggle_fullscreen = function ()
    vim.g.nvim_qt.fullscreen = not vim.g.nvim_qt.fullscreen

    if vim.g.nvim_qt.fullscreen then
        return '1'
        return '0'

--vim.cmd('call GuiWindowFullScreen(' .. toggle_fullscreen() ..')')
vim.keymap.set('n', '<F11>', ':call GuiWindowFullScreen(' .. toggle_fullscreen() ..')<CR>')

What I would expect, is the value of fullscreen to be toggled on each function call. It however always remains false. Can anyone explain why this happens?


  • I'm not 100% familiar with the Neovim-qt framework, but your toggle_fullscreen() function does seems to work fine. When running this locally, I get the toggling behavior.

    Could you provide some more information how the keymap exactly works? My guess is that the set() function simple runs the toggle_fullscreen once and saves it in the keymap as ":call GuiWindowFullScreen(0)", which leads you to always calling the function with a false value.