How do I scroll down half a page in Vim?
Answer
<C-d>
Explanation
The <C-d> (Ctrl+d) command scrolls the window down by half a screen, moving both the viewport and the cursor. It is one of the most efficient ways to move through a file quickly without losing your place.
How it works
<C-d>scrolls down by half the window height- The cursor moves along with the scroll, maintaining its relative position on screen
- The scroll amount is controlled by the
scrolloption (default is half the window height)
Example
If your terminal window shows 40 lines, pressing <C-d> scrolls down approximately 20 lines. The cursor also moves down 20 lines, keeping you oriented in the file.
Changing the scroll amount
You can change how many lines <C-d> scrolls by setting the scroll option:
:set scroll=10
Or prefix the command with a count: 15<C-d> scrolls down 15 lines and sets the scroll option to 15 for future use.
Tips
- Use
<C-u>to scroll up by half a page (the counterpart to<C-d>) - Use
<C-f>to scroll down a full page and<C-b>to scroll up a full page - Use
<C-e>to scroll the screen down by one line without moving the cursor - Use
<C-y>to scroll the screen up by one line without moving the cursor - Use
zzto center the screen on the current cursor position after scrolling - Unlike
<C-f>,<C-d>keeps better context because you can still see half of what was previously on screen