I want to stop Vim from scrolling (if that's the right word) when I split a window horizontally.
Let's say I edit a 10 line file in Vim. I have a single window onto the buffer and the window is 40 lines high. There's more than enough room for two windows, one on top of the other, with both showing the whole buffer. And let's say scrolloff
is set to 4.
When I split the window horizontally, the original window is scrolled so that exactly scrolloff
lines are shown between the top of the window and the line the cursor is on -- if there were more than scrolloff
lines between the top of the window and the cursor line -- even though there is no need to scroll.
Put another way, if the cursor is on line 1, 2, 3, 4 or 5 when I split the window, the original window doesn't "move" (good). But if the cursor is on line 6, the window scrolls so that line 2 becomes the top-most visible line...ensuring scrolloff
lines (4) are visible above the cursor line (annoying). Similarly if the cursor is on line 7 when I split the window, the original window scrolls to that line 3 becomes the top-most visible line. And so on.
Is there a way to configure Vim never to scroll the original window when I split it horizontally?
I imagine it's possible to map <C-W>s
to a function which does what I want, but I'd prefer to solve this by configuration if possible.
scrolloff
is 0 (i.e. has never been set). Alsoscrolloff
is supposed to be the minimal number of lines to keep above/below the cursor, not the exact number.set scrolloff=999
which is often used to keep the current line in the middle of the window. It seems to solve your problem but it can be super annoying.set nowrap
(withset wrap
it may scroll, but not too far) and it makes perfect sense because number of lines does not change. Making vim never scroll on horizontal split is impossible because number of lines will change. And you are wrong saying about “scrolling to exactlyscrolloffset
lines”: when splitting horizontally it tries to keep the proportion: if in 65 lines high window cursor is on 44’th line after split it is on 22’nd. Ifwinline()/2
appears to be lesser then or equal to&scrolloffset
then you will get your behavior.