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

How do I scroll the view horizontally so the cursor sits at the leftmost or rightmost visible column?

Answer

zs and ze

Explanation

When nowrap is set and lines extend beyond the screen width, zs and ze snap the horizontal scroll position so the cursor sits exactly at the left or right edge of the visible screen area. This complements the incremental scroll commands zh/zl and the half-screen scroll zH/zL.

How it works

  • zs — scroll the view so the cursor column is the first (leftmost) visible column
  • ze — scroll the view so the cursor column is the last (rightmost) visible column
  • Unlike zh and zl which scroll by a fixed amount, zs and ze snap directly to the cursor position
  • Only meaningful when set nowrap is active; with wrap they have no visible effect

Example

With a very long line and set nowrap:

[much text before]...current_var = some_long_expression...[much text after]
                   ↑ cursor here
  • Press zs — the view shifts so current_var is at the left edge of the screen
  • Press ze — the view shifts so current_var is at the right edge, showing more of what came before

Tips

  • Use zs after jumping to a deep column (e.g., after a /pattern search) to reveal context to the right
  • Use ze to peek at what precedes the cursor on a long line
  • zH / zL scroll half a screen width and don't depend on cursor position — useful for scanning long lines systematically

Next

How do I rename a variable across all case variants (snake_case, camelCase, MixedCase) at once?