If I press
zz in vim, my screen/view will center vertically on the cursor position.
How can I do the same, but horizontally? Is there a vim command for that?
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.Sign up to join this community
I have this mapping in my
" Horizontally center cursor position. " Does not move the cursor itself (except for 'sidescrolloff' at the window " border). nnoremap <silent> z. :<C-u>normal! zszH<CR>
This isn't a direct answer to the question, but potentially a different solution to the underlying problem. In my case, the problem was for really long lines, the right side falls off the screen and the cursor ends up far on the right side.
:set sidescrolloff=<number of characters>
Interestingly, if you just put a giant number in here, it appears to cap it up to the middle of your screen. In this way, you never have to do a "zz" equivalent because the cursor is always centered horizontally on the screen (except when you're hitting the left edge).
Just for completeness, if you wanted the equivalent vertically, you use
:set scrolloff=<number of lines>