How to move screen left/right or center it horizontally without moving cursor in vim?

I don't know about centering the screen horizontally around the cursor, but as far as moving the screen half a screen left/right, try this (from :help scroll-horizontal)

zL          Move the view on the text half a screenwidth to the
            right, thus scroll the text half a screenwidth to the
            left.  This only works when 'wrap' is off.  {not in
            Vi}


zH          Move the view on the text half a screenwidth to the
            left, thus scroll the text half a screenwidth to the
            right.  This only works when 'wrap' is off.  {not in
            Vi}

A nice configuration option that I am using is sidescrolloff, it's the opposite of scrolloff.

I am currently using them both in my .vimrc which is a setting I can't live without. Of course you can increase/decrease the offset(s) as desired. It kind of depends on the type of document(s) you are working on I guess :)

set scrolloff=20       " keep 20 lines visible above and below cursor at all times                                                                        
set sidescrolloff=30   " keep 30 columns visible left and right of the cursor at all times

Below some info from the Vim :help

scrolloff Minimal number of screen lines to keep above and below the cursor. This will make some context visible around where you are working.

sidescrolloff The minimal number of screen columns to keep to the left and to the right of the cursor if 'nowrap' is set.


You can also use:

zl and zh to move only one character

Tags:

Vim