macOS: Terminal scrolls past file boundaries When I have a file open in either the standard Terminal or iTerm2, I've noticed a weird problem. When I use the Trackpad to scroll through the file with two fingers, if I scroll to the top of the file and scroll a bit more, it goes past that and goes back into my Terminal command history.

I'd really like this behavior to not happen, and stop at the top/bottom of the file. I've only observed this in macOS and not Linux.

Is there a setting I need to tweak?
I managed to eventually find the settings to stop this behavior.

In Terminal, it was Preferences -> Profiles -> Keyboard and check the box for "scroll alternate screen"

In iTerm2, it was Preferences -> Advanced -> set "Scroll wheel sends arrow keys when in alternate screen mode" to Yes.