Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Always keep the cursor centered in Vim

Tags:

vim

I would like to keep my cursor centered at any time.

I manage, thanks to a high valued scrolloff as mentioned on this Vim Tips page, to keep it centered when there is line around the cursor but I can't make Vim behave that way when my cursor is near the first or last lines. Is it possible to make Vim adds the "tilde" ~ lines to replace "real lines"?

like image 774
Maxime Avatar asked Nov 15 '12 13:11

Maxime


2 Answers

You can try this mapping:

:nnoremap j jzz
:nnoremap k kzz

And if you often use G to jump to end of a file, you probably also want

:nnoremap G Gzz
like image 177
kev Avatar answered Sep 21 '22 15:09

kev


Exactly what made kev but if (like me) you're a silly full keyboard user, you can add

:nnoremap j jzz
:nnoremap k kzz
:nnoremap <Down> jzz
:nnoremap <Up> kzz

Thanks to @kev

like image 30
Metal3d Avatar answered Sep 19 '22 15:09

Metal3d