Evgenyt
Evgenyt

Reputation: 10741

How to force VIM/GVIM show last buffer line at the bottom (instead of top)?

If using mouse wheel (or scrollbar) to scroll to the bottom of current buffer, then VIM allows to "scroll bellow" the bottom of the file. So that the last line appears at the top of current buffer. This brings much pain for me as for VIM newbie used to deal with other editors (especially MS VS).

Is there any way to disable "scrolling below the bottom"?

Upvotes: 3

Views: 1419

Answers (3)

Sebastian Blask
Sebastian Blask

Reputation: 2938

If you don't mind that it moves the cursor, this works:

noremap <ScrollWheelUp> H5k
noremap <ScrollWheelDown> L5j

Upvotes: 0

milton
milton

Reputation: 1018

Adjust your scrolling offset with the following option.

:set scrolloff=NUMBER

Where NUMBER is the number of lines around the cursor.

Excerpt from Vim's embedded help system:

'scrolloff' 'so'        number  (default 0)
                    global                                                                                                                 
                    {not in Vi}
    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).
    For scrolling horizontally see 'sidescrolloff'.
    NOTE: This option is set to 0 when 'compatible' is set.

Upvotes: 1

John Hyland
John Hyland

Reputation: 6872

Well, if you type 'zb' in command mode, the current line goes to the bottom of the screen. That won't really prevent your problem, but it's at least a quick way to fix it when it happens.

Upvotes: 2

Related Questions