When switching back to a buffer (.e.g with Ctrl^ and
:bn, etc.), Vim tries to scroll whatever line the cursor was on last to the center of the window. I find this behavior extremely disorienting, so I use the code in the following link to just leave the window position exactly the way it was.
It works except in one edge case that I believe is because of a bug in Vim itself. Please follow these steps to re-create the issue (after adding the above Vimscript to your vimrc):
- Open a relatively long buffer (a couple hundred lines or so).
- Scroll the window all the way to the top of the buffer (line 1 of buffer at top of window).
- Move cursor to anywhere in the bottom half of the window, preferably the very last line by using L (line 1 of buffer should still be visible at top of window).
- Switch to another buffer using Ctrl^ or
:bn, then switch back.
Instead of leaving the window position exactly the way it was, Vim scrolls the window so the cursor line is in the middle of the window.
Any help would be greatly appreciated!
My System Info:
VIM - Vi IMproved 8.0 (2016 Sep 12, compiled Nov 10 2017 18:06:39) macOS version Included patches: 1-1250 Compiled by Homebrew Huge version without GUI.