scroll without cursor move (or: remember mark when scrollbar is used?)
A common complaint is that cursor always must be onscreen. The use-case for this could be satisfied by leaving a ~~jumplist entry~~ special mark at the cursor position before it is scrolled out of view using the scrollbars.
This feature is in Bram's todo.txt:
- STICKY CURSOR: Add a way of scrolling that leaves the cursor where it is.
Especially when using the scrollbar. Typing a cursor-movement command
scrolls back to where the cursor is.
Off-screen visual selections should also be allowed. (Currently selections are extended when scrolling too far.)
@pcworld If this is ever implemented, "sticky selections" would naturally be part of it. The "anchored" end of the selection isn't changed when scrolling. It's the cursor being pushed around that changes the non-anchored end of the selection.
If you know you're going to be scrolling, you can keep your selection by going back to normal mode before scrolling. When you want it back, type gv.
Ok I know it's possible (specifically, that these individual pieces are possible to code, but I am not an experienced enough plugin writer to do it effectively (I spent 2 hours debugging why I couldn't get mousemoveevents to work and then gave up)):
- Set
vim.o.scrolloffto0 - Setup a mouse reporting callback to update position whenever the mouse moves
- Obtain the window currently under the mouse
- Within this window, run custom scrollback code
- On scroll start, save position of original cursor and relative scroll
- Use
<C-e>and<C-y>until it's near off the screen - Hide the cursor completely while continuing to run
<C-e>etc - Once any input beside scrolling is issued, capture it, jump back to scroll start, and apply it The same logic could be used to capture off-screen VISUAL selections (by storing the selection made before scrolling started, then dynamically modifying/removing the current selection, but capturing any input and restoring the original scroll position and selection).
Sorry for my insane ramblings! Guess I'm switching back to ||VSCode|| for the time being :(
I described a very simple approach in the original issue above: Nvim can set a mark that remembers the cursor position just before scrolling starts. That allows a mouse gesture or keymap to restore the view back to that mark.
Agreed -- if this can be done natively, it would be much simpler. I was thinking about how you'd implement a plugin in the meantime; I tried to make one but realized there are a ton of nontrivial edge cases you have to worry about.
Any updates on this? The issue is nearly 11 years old.
No updates. We could close the issue and then it's zero years old, or we can keep it open to continue tracking it. The age of an issue is irrelevant, given that life-minutes are being used to do other things.