[vim/vim] Allow for keeping cursor centered at end of buffer with scrolloff (Issue #13428)

228 views
Skip to first unread message

jmp

unread,
Oct 26, 2023, 12:01:12 PM10/26/23
to vim/vim, Subscribed

Is your feature request about something that is currently impossible or hard to do? Please describe the problem.

It is difficult to edit the end of a file with a high scrolloff value set because the view is not kept centered. scrolloff is really useful for keeping the cursor centered at most times, but entering insert mode at the end of the file with a high value set will reset the view (even if you've intentionally scrolled with <C-e>) so that the last line of the buffer is near or at the bottom of the window (depending on the specific scrolloff value used). This issue does not exist with no scrolloff set, i.e. you can center with zz and the view will stay there when entering insert. Users with a high scrolloff set probably want to keep the cursor centered at all times (I do), but this currently cannot be done.

Describe the solution you'd like
A clear and concise description of what you want to happen.

I would like to be able to keep the cursor centered at the end of the buffer, even with a high scrolloff set, when entering insert mode, jumping, or scrolling. See these GIFs for a visual example:

  • Vim: scrolloff = 60

vim_centered

emacs_centered

In the first GIF, I am in vim and with a scrolloff value of 60 set. I G to the end of the file and open insert mode. Afterwards, I scroll with <C-e> and enter insert mode again. In the second GIF, I am in GUI Emacs with Evil, but using native settings that adjust where the cursor is kept. This behavior is essentially what I'm after.

Describe alternatives you've considered
There are existing plugins which attempt to but do not solve this. You can rewrite keymaps to attempt to keep the cursor centered, but that is a kludge that requires modifying many keymaps and doesn't work well. There is no existing solution that allows for this behavior that I'm aware of.

Additional context


Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/13428@github.com>

Christian Brabandt

unread,
Oct 27, 2023, 3:07:43 AM10/27/23
to vim/vim, Subscribed

@luukvbaal is this something that could be achieved using the 'splitkeep' option (and a bottomline value)? I may also be totally off, not sure if those two things are related 🤷

In any case this really sounds like a real nice use case here. Don't expect any work on that soon.


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/13428/1782408085@github.com>

luukvbaal

unread,
Oct 27, 2023, 6:54:29 AM10/27/23
to vim/vim, Subscribed

Hmm no, seems loosely related but I think both in concept and implementation, this strays too far from the 'splitkeep' option. The splitkeep mechanism only triggers when windows are resized. What's needed here is to adjust the 'scrolloff' logic in some move.c functions itself I think.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/13428/1782709065@github.com>

jmp

unread,
Oct 27, 2023, 10:16:11 AM10/27/23
to vim/vim, Subscribed

@luukvbaal I appreciate the direction. I've never contributed and don't know the codebase. With those instructions, I'd be willing to jump in and take a look


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/13428/1782992862@github.com>

Christian Brabandt

unread,
Nov 5, 2023, 9:12:45 AM11/5/23
to vim/vim, Subscribed

I believe there is a special case when reading from a channel and the callback is appending to the buffer, the cursor will automatically be set to the newline appended. It sounds like this is what you want for a more general case.

https://github.com/vim/vim/blob/da4e433dc3bee7fa521df3c7235d49a6732134ef/runtime/doc/channel.txt#L1250-L1252

See this part of the documentation. (I don't know currently where this is handled in the code however).


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/13428/1793749180@github.com>

Zeyad Moustafa

unread,
Dec 20, 2024, 10:47:01 AM12/20/24
to vim/vim, Subscribed

Any progress ? I need this for neovim but they are waiting for a patch from vim.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/13428/2557252173@github.com>

mcauley-penney

unread,
Dec 20, 2024, 11:29:26 AM12/20/24
to vim/vim, Subscribed

It's considered indecorous to ask for updates on open issues. Feel free to open a PR instead.

Chris, the primary maintainer, said to not expect any work on this feature soon, which I interpreted to mean that it is up to either me or another user to build this. I only started trying to understand the code base so I could implement this feature in the past month, so I have no progress yet, but I am working on this.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/13428/2557321791@github.com>

Christian Brabandt

unread,
Dec 20, 2024, 1:58:44 PM12/20/24
to vim/vim, Subscribed

Any progress ? I need this for neovim but they are waiting for a patch from vim.

It's open source. You get what you pay for


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/13428/2557555413@github.com>

Zeyad Moustafa

unread,
Dec 21, 2024, 2:57:40 AM12/21/24
to vim/vim, Subscribed

@chrisbra Please don't mind me I just don't know C or vimscript as I only use lua that's why I don't think that I can contribute to this right now. But of course if I had the time I would help to solve this.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/13428/2558041202@github.com>

mcauley-penney

unread,
1:13 AM (13 hours ago) 1:13 AM
to vim/vim, Subscribed
mcauley-penney left a comment (vim/vim#13428)

@chrisbra @luukvbaal I've created a draft PR for this (#19040). This PR still needs a lot of things, I think:

  1. new tests
  2. modification of old tests?
  3. documentation
  4. review for cases where this behavior could be a problem but which I have overlooked. For example, I saw that, for popups, the new option should be turned off. I assume there are at least some other places where this should be turned off, but I couldn't find any

I've never created a feature for Vim before, so I don't really know the process. It would be cool for maintainers to look at it and give me a signal that I'm moving in the right direction. I would eventually like others to try this and give their feedback too.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/13428/3695536587@github.com>

Reply all
Reply to author
Forward
0 new messages