vimtricks.wiki Concise Vim tricks, one at a time.

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 edge
  • zL — moves the viewport right by half the screen width, revealing content extending beyond the right edge
  • Both commands only have visible effect when :set nowrap is 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=5 maintains a horizontal margin of visible columns around the cursor when it moves near the edge
  • :set sidescroll=1 enables smooth single-column horizontal scrolling as the cursor approaches the edge
  • After pressing $ to reach the end of a long line, use zs to reposition the view so the cursor is at the leftmost visible column
  • In visual block mode across a wide file, zH and zL let you scroll and extend the selection without losing your block anchor

Next

How do I highlight only the line number of the current line without highlighting the entire line?