luaeditorconfigneovim

Neovim scroll option not persisting from config


I'd like to permanently set the scroll option in my Neovim config to a set value, but the option doesn't persist when I set it in my init.lua file.

~/.config/nvim/init.lua:

vim.o.scroll = 20

The docs have this to say about the scroll property:

"Will be set to half the number of lines in the window when the window size changes. This may happen when enabling the status-line or 'tabline' option after setting the 'scroll' option"

I haven't changed the status-line or tabline options, and I've tried setting scroll at the bottom of my config file. I suspect the size of the window is being changed at some point which is resetting the scroll property.

Is there a workaround for this? Or something I'm missing?

My config file for reference (based on the kickstart config):


Solution

  • The scroll option is unfortunately a local-noglobal config option.

    You could crea

    See :h local-noglobal or :h scroll

    Special local window options                    local-noglobal
    
    The following local window options won't be copied over when new windows are
    created, thus they behave slightly differently:
    
            Option          Reason
            'previewwindow' there can only be a single one
            'scroll'        specific to existing window
            'winfixbuf'     specific to existing window
            'winfixheight'  specific to existing window
            'winfixwidth'   specific to existing window
    

    A solution could be to create an autocommand on BufEnter and set scroll=n