vim – Scrolling in vim

zz – centers the current line cursor is on, to the middle of the screen
zt – top
zb – bottom

Since the space bar isn’t use in normal mode, map zz to it. This makes it easy when using “N” or “n”. Then you can quickly press space bar and it will center the found item to the center of the screen.

Put this into your .gvimrc file: nmap <space> zz

You could also do the following:

nmap n nzz
nmap N Nzz

You can also change how it scrolls by setting the amount of lines from the edge of the buffer you can go before it starts scrolling

:set scrolloff=1000 

This scrolls whenever you move the cursor, but you can set it to 10, for example, to scroll if it comes within 10 lines of the edge of the buffer.

Leave a Reply

You must be logged in to post a comment.