Search code examples
vim

Page starts scrolling when cursor reaches half page


When I move my cursor down, first it reaches the last line on the page, then the page starts scrolling. I remember seeing someone doing this, but instead of reaching the end of the page, it would start scrolling down when the cursor reached half the page length. How can I set this up?


Solution

  • What you saw was probably caused by setting the 'scrolloff' option to a large number:

    :set scrolloff=999
    

    Using it like this is suggested in Vim's own :help 'scrolloff':

    Minimal number of screen lines to keep above and below the cursor. This will make some context visible around where you are working. If you set it to a very large value (999) the cursor line will always be in the middle of the window (except at the start or end of the file or when long lines wrap).

    Of course, any number larger than half your screen lines will do, it doesn't have to be 999.

    You can put it in your vimrc to have it enabled by default.


    If you don't always want to center the current line but only do so once, use zz (see :help zz)

    For more ways to scroll, read :help scrolling.