Vim center auto search results

When I perform a search using vim or gvim, the resulting cursor positioning inside the window is somewhat random, landing too often on the last (or first) line in the window. A search for highlighting helps, but still it’s cumbersome to look around on the screen to find the cursor ... and it’s a little ironic that after vim finds the following result in some megabyte log file, I have to use ol 'neocortex to isolate it from the last 4K or so.

I can manually get the effect that I want by pressing "zz" after each search, but would rather process my _vimrc so that this happens automatically.

+4
source share
2 answers

Will this work for you?

:nmap n nzz :nmap p pzz 
+7
source

I use this trick for other commands too:

 nnoremap n nzz nnoremap N Nzz nnoremap <Co> <Co>zz nnoremap <Ci> <Ci>zz 
+2
source

All Articles