Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to let vim automatically scroll when moving the cursor at the bottom?

Tags:

vim

Let's assume I just opened a file in vim with many lines of text/code.

I jump to line 150 with :150 and then my cursor is down at the bottom of the screen and I may wonder how the next couple of lines look like.

I'd like to know about a setting to let vim's cursor never reach the last 4~6 lines of the screen, instead it should scroll the text upwards.

Is such a setting possible?

like image 926
arminfro Avatar asked Oct 28 '25 05:10

arminfro


1 Answers

Use

 set scrolloff=6

for 6 lines of scroll offset. From the vim help:

'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.
like image 74
Jens Avatar answered Oct 30 '25 08:10

Jens



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!