I used to have these lines in my old vimscript config which allowed me to scroll a third of the window height (instead of the default half) with Ctrl+d
and Ctrl+u
:
" Scroll by a third of window height (https://stackoverflow.com/a/16574696/1706778)
execute "set scroll=" .&lines / 3
au VimResized * execute "set scroll=" . &lines / 3
I ported it to my new lua config file as follows:
-- Scroll by a third of window height (https://stackoverflow.com/a/16574696/1706778)
vim.cmd [[ execute "set scroll=" .&lines / 3 ]]
vim.cmd [[ au VimResized * execute "set scroll=" . &lines / 3 ]]
However, the VimResized
event doesnât seem to trigger.
I tried this simpler autocommand:
vim.cmd [[ au VimResized * echo "Vim Resized!" ]]
but whenever I create a horizontal split, or change the size of the window, the text is not printed.
Any idea what could be the problem?
EDIT: Iâm also noticing that the scroll
option is being reseted when a split window is closed, and itâs not the autocommand that I defined thatâs doing it.
EDIT 2: For the question above, I did find the answer in the docs:
*'scroll'* *'scr'*
âscrollâ âscrâ number (default: half the window height)
local to window
Number of lines to scroll with CTRL-U and CTRL-D commands. 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.
If you give a count to the CTRL-U or CTRL-D command it will
be used as the new value for âscrollâ. Reset to half the window
height with â:set scroll=0â.
So it is being reseted by nvim when the window size changes. The question is: How can I override it so that it sets scroll to 33% of the current window size.