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 communityIf 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?
There's no single Vim command, but you can combine zs
with zH
: Scroll to position the cursor at the left side of the screen, then scroll half a screenwidth to the right.
I have this mapping in my ~/.vimrc
:
" 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>