Always keep the cursor centered in Vim

vim

Solution

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

Problem

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"?

Original source