How do I scroll the view horizontally by half a screen width in Vim?
Answer
zH and zL
Explanation
zH and zL scroll the viewport horizontally by half a screen width, letting you navigate wide content efficiently when wrap is disabled. This pair complements the single-column variants zh and zl, giving you a way to jump across long lines without holding down a key repeatedly.
How it works
zH— moves the viewport left by half the screen width, revealing text scrolled off the left edgezL— moves the viewport right by half the screen width, revealing content extending beyond the right edge- Both commands only have visible effect when
:set nowrapis active; with wrapping on, lines always fit the screen
The single-column counterparts are zh (scroll left one column) and zl (scroll right one column). For snapping the view so the cursor sits at a screen edge, use zs (snap cursor to left edge) or ze (snap cursor to right edge).
Example
With a wide CSV or log file open and :set nowrap, only the leftmost columns may be visible:
id,name,email,phone,address,city,state,zip
^-- cursor here; everything right of "zip" is hidden
After pressing zL (scroll view right half a screen):
email,phone,address,city,state,zip,country
^-- same cursor row, new columns visible on right
Press zH to scroll the view back left and see the original columns.
Tips
:set sidescrolloff=5maintains a horizontal margin of visible columns around the cursor when it moves near the edge:set sidescroll=1enables smooth single-column horizontal scrolling as the cursor approaches the edge- After pressing
$to reach the end of a long line, usezsto reposition the view so the cursor is at the leftmost visible column - In visual block mode across a wide file,
zHandzLlet you scroll and extend the selection without losing your block anchor