Mouse scroll stopped working with Less in Terminal
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:
- Unix & Linux: Neither 'less' or 'less -X' clear screen on exit
- SuperUser: Less command clearing screen upon exit
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 toFRX
(ifLESS
environment variable is set, Git does not change it at all). If you want to selectively override Git’s default setting forLESS
, you can setcore.pager
to e.g.less -S
. This will be passed to the shell by Git, which will translate the final command toLESS=FRX less -S
. The environment does not set theS
option but the command line does, instructing less to truncate long lines. Similarly, settingcore.pager
toless -+F
will deactivate theF
option specified by the environment from the command-line, deactivating the "quit if one screen" behavior ofless
.
(emphasis mine)
TLDR:
-
git
is the one setting$LESS
environment variable toFRX
if empty - scrolling in
less
doesn't work withX
option set - unset the default
X
option withgit config --global --add core.pager "less -+X"