Question

For a few years now, Terminal.app in MacOS has supported mouse-scrolling with the less program, but today I noticed that it is no longer accepting mouse scrolls, and only works with the Up and Down keys now.


What's not working:

less and all other programs that use it are not accepting mouse scrolls. Instead, it scrolls the terminal window. These 'other' programs are:

  • man
  • git log
  • diff

Previously, less would also clear the screen when closing it (q), but now the text remains on the screen.


What I've tried:

  • Tested other programs: vim for example, still accepts mouse scrolls
  • Used other Terminal emulators: less is not accepting mouse scrolls on Hyper either
  • Tested on another machine over SSH: Connected to one of my VPSes, and used less there within the Terminal app. Mouse-scrolls are working with it.
  • Used a newer version of less: Installed the latest version (530) of less using Homebrew, but it's not working with mouse scrolls either.

So I'm not sure what's wrong. Would greatly appreciate any help to make less accept mouse scrolls again.

Was it helpful?

Solution

After going through a few other answers, I've realized there is a $LESS environment variable that contains default flags.

It's empty on my other Mac and Ubuntu system, but for some reason it's equal to -FRX on this machine, and that's causing these issues:

  • -X caused it to NOT accept mouse scrolls
  • -F caused it to automatically exit for small files

Which is weird, since I never changed it, so it must've been modified by some other program. Anyways, manually setting it in my .rc files fixed the issue:

export LESS="-R"

Sources:

OTHER TIPS

In case you're using less inside git (through git log or similar):

git-config docs have the answer:

When the LESS environment variable is unset, Git sets it to FRX (if LESS environment variable is set, Git does not change it at all). If you want to selectively override Git’s default setting for LESS, you can set core.pager to e.g. less -S. This will be passed to the shell by Git, which will translate the final command to LESS=FRX less -S. The environment does not set the S option but the command line does, instructing less to truncate long lines. Similarly, setting core.pager to less -+F will deactivate the F option specified by the environment from the command-line, deactivating the "quit if one screen" behavior of less.

(emphasis mine)

TLDR:

  • git is the one setting $LESS environment variable to FRX if empty
  • scrolling in less doesn't work with X option set
  • unset the default X option with git config --global --add core.pager "less -+X"
Licensed under: CC-BY-SA with attribution
Not affiliated with apple.stackexchange
scroll top