Use mouse wheel to scroll less in iTerm2

在 iTerm2 中使用 less command 有一个奇怪的点:你不能用鼠标来滚动页面。只能使用 Vim 的 keybinding Ctrl+d 和 Ctrl+u 来上下翻页。而且当你比如在查看一个 command 的 man page 时,因为 man page 默认是使用 less 来打开的,你查看完某个 man page 按 q 退出,然后使用鼠标滚轮往上面滚一下,滚到上面一屏,你会发现你的 Terminal 变得很乱,有很多刚刚你查看的那个 man page 的残留。 我的需求总结来说就是: 能够在 less 里使用鼠标滚轮来翻页,滚动。 退出 less 之后不要有残留。 其实,这里有一个概念叫作 alternate screen。你用 less 打开查看一个什么文件的时候进入的就是一个 alternate sceen,按 q 退出就是退出那个 alternate screen,回到 normal screen。Alternate screen 就是一个单独的 buffer,独立于当前 terminal 的。 When activated, the current screen is saved and replaced with the alternate screen....

2023-12-17