Learn Practice Daily golf Reference

How to scroll and page down in Vim

In Normal mode, press Ctrl-f to page down and Ctrl-b to page up, or Ctrl-d and Ctrl-u to scroll half a page. zz puts the cursor's line in the middle of the screen.

KeysWhat it does
Ctrl-f / Ctrl-bPage down / page up: a whole screen forwards or backwards. The Page Down and Page Up keys do the same.
Ctrl-d / Ctrl-uScroll down / up half a screen; the cursor moves the same number of lines.
Ctrl-e / Ctrl-yScroll one line down / up. The cursor stays on its line unless it would leave the screen.
zzScroll so the cursor's line is in the middle of the screen. The cursor doesn't move.
zt / zbScroll so the cursor's line is at the top / the bottom of the screen.
H / M / LThe opposite: the page stays put and the cursor goes to the top, middle or bottom line of the screen.
3Ctrl-eThree lines at once: Ctrl-e, Ctrl-y, Ctrl-f and Ctrl-b all take a count.
21import { db } from './db';
20
19export function findUser(id) {
18 return db.get('users', id);
17}
16
15export function findOrders(userId) {
14 return db.list('orders', { userId });
13}
12
11export function total(orders) {
10 let sum = 0;
9 for (const o of orders) sum += o.amount;
8 return sum;
7}
6
5export function average(orders) {
4 if (orders.length === 0) return 0;
3 return total(orders) / orders.length;
2}
1
22export function latest(orders) {
1 return orders.toSorted((a, b) => b.date - a.date)[0];
2}
3
4export function summary(userId) {
5 const orders = findOrders(userId);
6 return {
7 count: orders.length,
8 total: total(orders),
9 average: average(orders),
10 latest: latest(orders),
11 };
12}
NORMALLoading the editor…22:1
Practise the keys

Scroll from memory

Press the keys for each one, as you would in Vim.

Page down: a whole screen forwards.
scroll here, then press the keys
1 of 7
Page down: a whole screen forwards.

A page or half a page?

Ctrl-d and Ctrl-u are the ones most people use for reading. Half a screen is small enough that your eye can follow the text as it moves, and the cursor comes along by the same number of lines, so it stays on what you were reading. Ctrl-f and Ctrl-b turn a whole screen at once, which is faster for skimming a long file but easy to lose your place in.

Often you don't need to scroll at all. If you know where you are going, G with a line number, a search with /, or } to the next blank line gets there in one move, and zz then brings the line into the middle of the screen.

Some lines above and below the cursor

The scrolloff option keeps that many lines visible above and below the cursor, so it never sits right at the edge of the screen: :set scrolloff=8 and ↵, or put set scrolloff=8 in ~/.vimrc (vim.opt.scrolloff = 8 in Neovim's init.lua). Vim's defaults.vim sets it to 5; Neovim starts at 0. A very large value, like 999, keeps the cursor's line in the middle of the screen all the time.