When I'm searching my document with / when the next match line is off screen, the cursor jumps down so that the matched line is the very last line in the window. For example, if I'm searching for countWordsWithMap in this sample file, it looks like this:


Is there any way to make it so the cursor jumps to the line where the match is found, but the window moves below that by a certain amount? For example, if I set the value to 10, the cursor should move to the match on line 59, but the window would jump to line 69, like this:


Basically, I always want the few lines below the match to be visible, unless the match is at the end of the file.

  • 2
    zz is your friend (see :h zz). Jul 7, 2016 at 16:02

1 Answer 1


Yes you have an option for that:

set scrolloff=10

This will always (or at least, when it's possible) leave 10 line above and below the cursor. When scrolling, searching, jumping, ...

It's worth knowing the same for horizontal:

set sidescrolloff=10
  • Out of curiosity, can this be made to work in only 1 direction? i.e. always keep 10 lines below the cursor, but the cursor may be at the top of the window?
    – ewok
    Jul 7, 2016 at 16:07
  • I don't think so, the documentation says explicitly Minimal number of screen lines to keep above and below the cursor.
    – nobe4
    Jul 7, 2016 at 16:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.