Skip to content

Implement relative scrolloff#45

Open
danielzuncke wants to merge 3 commits into
Aasim-A:masterfrom
danielzuncke:implement-relative-scrolloff
Open

Implement relative scrolloff#45
danielzuncke wants to merge 3 commits into
Aasim-A:masterfrom
danielzuncke:implement-relative-scrolloff

Conversation

@danielzuncke

Copy link
Copy Markdown

Copied from the Issue description, didn't know this gets another description:

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.

Closes #44

It overwrites scrolloff if it is set: allows keeping regular scrolloff
in nvim config in case the plugin is removed or relative is turned off.

Update README.md with new behavior and config.

Why
^^^
When using a large scrolloff (ex. 1/3 of window_height) and using split
windows, the code becomes very jumpy: after even one horizontal split,
every vertical cursor movement will trigger the code to move.

Calculating the scrolloff based of the current selected nvim window
height keeps a "stable" section of code in the center of the window.
Old
^^^
VimResized: I believe this fires if the height / width of the Neovim
application changes, ex. resizing the Terminal running Neovim.

BufEnter: If there are multiple windows showing the same buffer, this
won't fire when switching between them.

New
^^^
WinResized: After a window in the current tabpage changed width or
height.

WinEnter: This fires when a window is entered.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add scrolloff relative to current window height

1 participant