1

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.

http://vim.wikia.com/wiki/Avoid_scrolling_when_switch_buffers

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):

  1. Open a relatively long buffer (a couple hundred lines or so).
  2. Scroll the window all the way to the top of the buffer (line 1 of buffer at top of window).
  3. 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).
  4. 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.
  • Does the original version at the top of the linked page work correctly for your edge case? – Rich Nov 15 '17 at 15:14
  • No the original doesn't work either. – Niko Bellic Nov 16 '17 at 6:01

Your Answer

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

Browse other questions tagged or ask your own question.