Search code examples
vim

Keep cursor line vertically centered in vim


I want the cursor to be constantly in the middle of my screen in vim.
I am not very comfortable looking constantly down to the end of the file.
What commands in the config will you advise to solve the problem?


Solution

  • Besides :set so=999, I also tried these 2 commands to map the normal k and j to "scroll up/down one line and place that line at the center of the window":

    :nnoremap k kzz
    :nnoremap j jzz
    

    A little different from setting so, when moving cursor down to the end of the file, it still remains at the center. However it doesn't affect the behavior of shift+g.