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

How do I scroll the view left and right when lines are wider than the screen?

Answer

zl

Explanation

When nowrap is set and lines extend beyond the screen width, Vim provides dedicated horizontal scroll commands. Unlike moving the cursor, these commands shift the viewport without necessarily moving the cursor, giving you precise control over which portion of long lines is visible.

How it works

Command Action
zl Scroll right by one character
zh Scroll left by one character
zL Scroll right by half a screen width
zH Scroll left by half a screen width
zs Scroll to place the cursor at the left edge of the screen
ze Scroll to place the cursor at the right edge of the screen

All commands accept a count: 5zl scrolls right 5 characters.

Example

With set nowrap and a file containing a very long line:

function processLargeDataset(inputPath, outputPath, transformFn, options) {

If only the beginning is visible, zL jumps half a screen right to reveal the rest. ze then aligns the cursor character to the screen's right edge.

Tips

  • These commands only have effect when nowrap is set — with wrap, all content is already visible
  • set sidescroll=1 makes zl/zh scroll one column at a time (the default is often 0, which jumps)
  • set sidescrolloff=5 keeps 5 columns of context visible when the cursor reaches the edge, similar to how scrolloff works vertically
  • For diffing wide files: :set nowrap followed by zl/zh to scroll both splits in sync

Next

How do I set a bookmark that persists across different files and Vim sessions?