I often find myself wanting to scroll a Vim window so that the line I'm on is roughly a quarter of the screen down—it provides more room to breathe than zt, but has more code displayed than zz. It's also helpful when my cursor is at the start of a function I want to read, but zt will cut off the Javadoc-like comments.
Is there some magic I can use to do this? I'm afraid I don't understand Vim's scripting at all.
Perhaps set scrolloff=5
(or how many lines above and below the cursor you would like) will do the trick for you. It isn't exactly what you asked for, but close enough?
You could use:
nnoremap <expr> zT 'zt' . winheight(0)/4 . '<c-y>'
nnoremap <expr> zB 'zb' . winheight(0)/4 . '<c-e>'
which will remap zT to zt followed by the quarter of current window height and CTRL-Y (which scrolls one line up, leaving cursor where it is).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With