Thursday, December 16, 2010

Make (next) found match to appear in the screen's center

Turned out to be easier than expected:

nnoremap n nzz
nnoremap N Nzz


Simply adds the zz (see :h z.) to n and N commands.

P.S. Original question and answer as SO.

Edit1 Problem with the solution is that the message search hit BOTTOM, continuing at TOP, due to the zz command, now doesn't appear on the screen anymore. Trying now to use the other tip: set scrolloff=5. Will see how that works.

Edit2 Yep, the set scrolloff=5 works for me much better than the nzz.

1 comment:

Unknown said...

I use this line in my vimrc:

execute 'set scrolloff='.(&lines-2)

It sets the scroll offset to show the current line in the center of the window all the time (the subtraction of 2 is to make room for the status & command bar)