Emacs: PageUp PageDown and return to the initial position


In Emacs, why I press PageUp and then PageDown, the cursor does not return to the initial position, but some other place on the page. Is there any way to make it do this? For example, have PageUp and PageDown just move the cursor up or down the number of rows visible.

Set the variable scroll-preserve-screen-position.

A value of t means point keeps its screen position if the scroll command moved it vertically out of the window, e.g. when scrolling by full screens.

Recent versions of Emacs will also preserve the current column even if that column doesn't exist in the intermediate position.