Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automatically scroll screen in vim when near top/bottom?

Tags:

vim

editor

I would like to have smarter screen scrolling when I'm editing. When I reach within X number of lines from the top/bottom of the screen, I would like it to scroll the screen as I continue moving the cursor (so I can always see, at minimum, X lines below or above).

I know ctrl-y and ctrl-e will scroll, but is there a way I can have vim detect when I hit j or k how far I am from the top/bottom of the screen so it can move the screen as needed? I also know zz will center on the current cursor location, but I'd like there to be an area where it doesn't scroll.

Thanks.

like image 997
CMB Avatar asked Jun 11 '09 16:06

CMB


2 Answers

From my .vimrc:

set scrolloff=3 " Keep 3 lines below and above the cursor 
like image 143
John G Avatar answered Oct 10 '22 17:10

John G


You might to also look at scrolljump which sets the number of lines scrolled when hitting the "border" set by scrolljump.

like image 32
Rob Wells Avatar answered Oct 10 '22 17:10

Rob Wells