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

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 resize
  • scroll=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 the scroll value, and also permanently sets scroll to 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 by scroll)
  • <C-f> and <C-b> always scroll a full page — they are independent of scroll
  • 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 the scroll value as a side effect

Next

How do I enable an alternative digraph entry mode where I type two characters then backspace?