tags:

views:

398

answers:

3

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.

+28  A: 

From my .vimrc:

set scrolloff=3 " Keep 3 lines below and above the cursor
Johnny G
awesome, it works! thank you!
rascher
exactly what I was looking for -- thanks!
CMB
Great stuff! (-:
Rob Wells
Indeed. This is a helpful tip.
ayaz
+1  A: 

G'day,

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

cheers,

Rob Wells
+1  A: 

Try scrolloff=9999. After cursor reaches middle of the screen, pressing 'j' moves the screen up by one, instead of moving the cursor down. Works great once you get used to it.