Next: Recentering, Up: Display [Contents][Index]

### 14.1 Scrolling

If a window is too small to display all the text in its buffer, it displays only a portion of it. Scrolling commands change which portion of the buffer is displayed.

Scrolling forward or up advances the portion of the buffer displayed in the window; equivalently, it moves the buffer text upwards relative to the window. Scrolling backward or down displays an earlier portion of the buffer, and moves the text downwards relative to the window.

In Emacs, scrolling up or down refers to the direction that the text moves in the window, not the direction that the window moves relative to the text. This terminology was adopted by Emacs before the modern meaning of “scrolling up” and “scrolling down” became widespread. Hence, the strange result that `PageDown` scrolls up in the Emacs sense.

The portion of a buffer displayed in a window always contains point. If you move point past the bottom or top of the window, scrolling occurs automatically to bring it back onscreen (see Auto Scrolling). You can also scroll explicitly with these commands:

`C-v`
`next`
`PageDown`

  Scroll forward by nearly a full window (`scroll-up-command`).

`M-v`
`prior`
`PageUp`

  Scroll backward (`scroll-down-command`).

`C-v` (`scroll-up-command`) scrolls forward by nearly the whole window height. The effect is to take the two lines at the bottom of the window and put them at the top, followed by lines that were not previously visible. If point was in the text that scrolled off the top, it ends up on the window’s new topmost line. The `next` (or `PageDown`) key is equivalent to `C-v`.

`M-v` (`scroll-down-command`) scrolls backward in a similar way. The `prior` (or `PageUp`) key is equivalent to `M-v`.

The number of lines of overlap left by these scroll commands is controlled by the variable `next-screen-context-lines`, whose default value is 2. You can supply the commands with a numeric prefix argument, n, to scroll by n lines; Emacs attempts to leave point unchanged, so that the text and point move up or down together. `C-v` with a negative argument is like `M-v` and vice versa.

By default, these commands signal an error (by beeping or flashing the screen) if no more scrolling is possible, because the window has reached the beginning or end of the buffer. If you change the variable `scroll-error-top-bottom` to `t`, the command moves point to the farthest possible position. If point is already there, the command signals an error.

Some users like scroll commands to keep point at the same screen position, so that scrolling back to the same screen conveniently returns point to its original position. You can enable this behavior via the variable `scroll-preserve-screen-position`. If the value is `t`, Emacs adjusts point to keep the cursor at the same screen position whenever a scroll command moves it off-window, rather than moving it to the topmost or bottommost line. With any other non-`nil` value, Emacs adjusts point this way even if the scroll command leaves point in the window. This variable affects all the scroll commands documented in this section, as well as scrolling with the mouse wheel (see Mouse Commands); in general, it affects any command that has a non-`nil` `scroll-command` property. See Property Lists in The Emacs Lisp Reference Manual.

Sometimes, particularly when you hold down keys such as `C-v` and `M-v`, activating keyboard auto-repeat, Emacs fails to keep up with the rapid rate of scrolling requested; the display doesn’t update and Emacs can become unresponsive to input for quite a long time. You can counter this sluggishness by setting the variable `fast-but-imprecise-scrolling` to a non-`nil` value. This instructs the scrolling commands not to fontify (see Font Lock) any unfontified text they scroll over, instead to assume it has the default face. This can cause Emacs to scroll to somewhat wrong buffer positions when the faces in use are not all the same size, even with single (i.e., without auto-repeat) scrolling operations.

The commands `M-x scroll-up` and `M-x scroll-down` behave similarly to `scroll-up-command` and `scroll-down-command`, except they do not obey `scroll-error-top-bottom`. Prior to Emacs 24, these were the default commands for scrolling up and down. The commands `M-x scroll-up-line` and `M-x scroll-down-line` scroll the current window by one line at a time. If you intend to use any of these commands, you might want to give them key bindings (see Init Rebinding).

Next: Recentering, Up: Display [Contents][Index]