I want to be able to control/sync the movement (scrolling) of the number column (usable with :set number) with another different window (which doesn't have :set number set).

Any ways to do this?


Yes. Choose one:

:windo se scb
:windo set scrollbind

This sets scrollbind for every window. :help scrollbind:

See also |scroll-binding|.  When this option is set, the current
window scrolls as other scrollbind windows (windows that also have
this option set) scroll.

Scroll-binding is definitely an option, but there are some downsides to it in that you might create interference with the use of scrollbind elsewhere, for instance if you're also using a diff at the same time...

From previous questions, I understand your use case is to use custom line numbering covering specific blocks of your buffer, and you're considering using a pop-up window to cover the line numbers and print your line numbers there.

In that case, consider that scrolling is not the only management you might need to do of the pop-up window and its buffer. You might also need to resize it or move it as the original window is resized or moved. You might need to renumber lines if the blocks in the original window change. You might need to extend the buffer in the pop-up as you append more text to the original window.

So perhaps a more encompassing approach is to use a set of auto-commands and use those to perform full management of your pop-up window, including scrolling or positioning it correctly according to the current buffer's position.

There are many events that look interesting and promising for your use case, the SafeState one probably being the most promising one. CursorMoved is also an interesting one, but remember there are ways to scroll without moving the cursor (<C-E> and <C-Y> in Normal mode, or the scrollwheel of the mouse if you have it configured.) Perhaps some events for insert mode are relevant too. And perhaps some events regarding the window gaining or losing focus too. And, of course, when it gets resized.

Some of these events might fire too often, so you might want to ensure you're saving the current state in some window or buffer variables, and then start handling the event by comparing your current state with the saved one from the last update. That way you can short-circuit out of the event handler when you're sure there's nothing to be done, and you keep the event handler (relatively) cheap on cases where it doesn't need to perform any updates.

  • 1
    Thanks for this detailed insight! It's true that I'll need to figure out a decent amount of things, though i plan on keeping the resizing handling as the last thing to do, since i don't really plan on resizing the windows for now. Putting the numbers on the popup window will need to be done using text marker/or just inspire myself from the partnumber.vim plugin. For the scrolling, i did thought of using the scroll option from popup though, that doesn't work as expected. :D – Nordine Lotfi Sep 15 '20 at 20:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.