After e.g. pasting in-line my window is showing a far right part of the document (column >80).
With leaving my cursor at the current position, how do I center the screen horizontally around it. Alternatively can I move the screen half a screen width further left, avoiding a fixed number as in e.g. 44zh
?
While the title is non-specific all answers deal with only moving up/down: How to move screen 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}
You can also use:
zl
and zh
to move only one character
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With