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
nowrapis set — withwrap, all content is already visible set sidescroll=1makeszl/zhscroll one column at a time (the default is often 0, which jumps)set sidescrolloff=5keeps 5 columns of context visible when the cursor reaches the edge, similar to howscrolloffworks vertically- For diffing wide files:
:set nowrapfollowed byzl/zhto scroll both splits in sync