How do I scroll the view left or right without moving the cursor in Vim?
Answer
zl and zh
Explanation
When a line is longer than the window width and wrap is off, Vim can display only part of it. The zl and zh commands let you scroll the view horizontally one character at a time without changing the cursor position, so you can inspect the hidden portion of long lines.
How it works
zl— scroll the view left (content moves left, revealing characters to the right)zh— scroll the view right (content moves right, revealing characters to the left)zL— scroll half a screen width to the leftzH— scroll half a screen width to the right- A count prefix multiplies the scroll distance:
5zlscrolls 5 characters at once
These commands only work when nowrap (:set nowrap) is active; with wrap on, all content is already visible.
Example
With a very long CSV line:
id,name,email,phone,address,city,country,postal_code,created_at
If only the first 40 characters are visible, press 5zl to scroll five characters to the right, then zL to jump half a screen further.
Tips
- Use
zeto scroll so the cursor is at the right edge of the window, andzsto scroll so the cursor is at the left edge — great for recentering long lines. - Combine with
g$(move to last visible character) andg0(move to first visible character) when navigating wrapped-off lines. - For structured data files with many columns,
:set nowrap+zl/zhis often more readable than toggling wrap.