Scroll window halfway between zt and zz in Vim

I often see that I want to scroll the Vim window so that the line I was working on is about a quarter of the screen down, it provides more breathing space than z t, but has more code displayed than z z. It is also useful when my cursor is at the beginning of the function I want to read, but z tdisables comments like Javadoc.

Is there any magic I can use to do this? I'm afraid I don't understand Vim scripts at all.

+5
source share
2 answers

Perhaps set scrolloff=5(or how many lines above and below the cursor you would like) will do the trick for you. This is not quite what you requested, but close enough?

+9
source

You can use:

nnoremap <expr> zT 'zt' . winheight(0)/4 . '<c-y>'
nnoremap <expr> zB 'zb' . winheight(0)/4 . '<c-e>'

which will reassign zT to zt, followed by a quarter of the current window height and CTRL-Y (which scrolls one line up, leaving the cursor where it is).

+6
source

All Articles