Skip to content

Add scrolloff relative to current window height #44

@danielzuncke

Description

@danielzuncke

Hi, I have the following (expected) behavior which is kind of annoying:
I like a scrolloff value of ~1/3 of the screen, so that the code I am looking at stays in the middle but also doesn't move on every vertical cursor movement. This works fine until horizontal splits get introduced: then the safety scrolloff half-of-height kicks in (for others maybe after more).
With the safety scrolloff the code becomes very "jumpy", as every vertical cursor movement moves the code while the cursor stays centered.

I want to propose an option in the plugin config to set a scrolloff relative to the height of the current window. The option controls the relative distance: relative = 3 means scrolloff = current_win_height / 3.

As relative is more specialized than scrolloff, I think if both a scrolloff is set and relative is given to .setup(), the relative distance should be used.
In this case one can leave scrolloff in the config in case the plugin gets removed later. Also it's annoying to try out features of the plugin and having to change your regular nvim config to make it work.


I have implemented this and fixed a related problem in the same branch: the 2 events VimResized, BufEnter on which a scrolloff recalculation happens should be WinResized and WinEnter (I think those were the intended ones anyways):

  • VimResized doesn't fire when resizing windows; ex. if there are multiple horizontal windows and one is made smaller vertically C-w20-, then the recalculation isn't triggered (neither relative, nor safety half-of-height).
  • BufEnter doesn't fire when a new window is entered that shows the same underlying buffer; ex. (horizontal) :split.

This is fixed with:

  • WinResized fires after a window resizing (which would also happen on VimResized, at least if relevant).
  • WinEnter fires when any other window is entered, regardless of underlying buffer.

Also there was a line indented with tab instead of spaces.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions