How do I control how many lines Ctrl-U and Ctrl-D scroll?
Answer
:set scroll=10
Explanation
The scroll option determines how many lines <C-u> (scroll up) and <C-d> (scroll down) move the viewport. By default it is set to half the window height (0 = auto-half), but you can fix it to a specific line count to get consistent, predictable scrolling regardless of window size.
How it works
scroll=0(default) — uses half the current window height; changes dynamically when you resizescroll=N— always scrolls exactly N lines, which stays constant even as the window size changes<C-u>and<C-d>both use this same value- A count prefix overrides it temporarily:
5<C-u>scrolls 5 lines regardless of thescrollvalue, and also permanently setsscrollto 5
Example
:set scroll=10 " always scroll 10 lines with Ctrl-U / Ctrl-D
:set scroll=0 " restore dynamic half-window behavior
:set scroll? " show current value
Useful for large monitors where the default half-page scroll jumps too far, or for small terminals where you want more context on each keypress.
Tips
- Use
<C-e>/<C-y>for single-line scrolling (unaffected byscroll) <C-f>and<C-b>always scroll a full page — they are independent ofscroll- If you resize the window while
scroll=0, Vim automatically recalculates to the new half-height - When using count prefix with
<C-u>/<C-d>, remember that it permanently changes thescrollvalue as a side effect