dotancohen
dotancohen

Reputation: 31471

VIM: Stay away from the edges on searches

I recently saw some VIM configuration where search matches would scroll to N lines past the match, so that there would be N lines below the search match instead of it being on the last line (to give context). I cannot find the page where this was mentioned, and apparently I do not know the right keywords to google for!

What is this feature called, and how could I have used the VIM manual to find it assuming that I don't know what it is called?

Thanks.

Upvotes: 3

Views: 543

Answers (1)

Steve McKinney
Steve McKinney

Reputation: 3361

As far as I tell this can't be set just for search, but is a setting that will be used in all situations.

You are looking for scrolloff: Minimal number of screen lines to keep above and below the cursor. This will make some context visible around where you are working. sidescrolloff does the same thing but horizontally.

This is what I have in my .vimrc:

" When the page starts to scroll, keep the cursor 8 lines from the top and 8
" lines from the bottom and 15 lines on the left
set scrolloff=8
set sidescrolloff=15
set sidescroll=1

Upvotes: 6

Related Questions