38

I have two computers with the latest Fedora. On the first, I'm using zsh and the mouse wheel can be used with the less pager within gnome-terminal to scroll the pager.

On the second, I use bash and the mouse whell scroll the terminal history, not the pager.

The shell shouldn't make any difference, why can't I use the mouse wheel to scroll in the second case?

To illustrate what it does, imagine I have a document like this:

AAAA
BBBB
CCCC
DDDD
EEEE

And I have a two line terminal. If I use less, I get on the screen

AAAA
BBBB

The mouse wheeel cannot scroll further down. If I scroll upwards, I get the bash prompt history. Now I use the page down key to get to the bottom of the document, I get on screen:

DDDD
EEEE

Scrolling upwards gets me

BBBB
DDDD

-->

1

4 Answers 4

28

The computer where less scrolled had LESS=-r, the other had LESS=-asXFMMRqix8.

From the less man page:

-q or --quiet or --silent

      Causes moderately "quiet" operation: the terminal bell is not rung if an attempt is made to scroll past the end of the file or before the beginning of the file.  If the terminal has a "visual bell", it is used instead.  The bell will be rung on certain other errors, such as typing an invalid character.  The default is to ring the terminal bell in all such cases.

-X or --no-init

      Disables sending the termcap initialization and deinitialization strings to the terminal.  This is sometimes desirable if the deinitialization string does something unnecessary, like clearing the screen.

The -X option prevented scrolling all together and the -q option caused the pager to enter a non-scrollable state when scrolling past the beginning or end of file.

My options are now LESS=-asrRix8.

2
  • 4
    Ugh. So disappointing: I love -XE, because I love having small files immediately dumped at the prompt, i.e. using less as a cat replacement for small files. I wish I could have -XE behaviour with scrolling on longer files … e-mailed the author in hopes this is something achievable. I suspect not. >: Jan 26, 2016 at 21:59
  • 3
    I use export LESS='-RiF --mouse --wheel-lines=3'.
    – HappyFace
    Aug 16, 2020 at 15:54
20
export LESS='--mouse --wheel-lines=3'
5
  • 1
    Please add context to this answer (i.e. what file this should be added to or if you're intending for it to be entered directly into a terminal as a standalone command)
    – JW0914
    Jan 5, 2020 at 16:09
  • 1
    Also worth mentioning that this solution requires version 5.4.3+ of less
    – ivan
    Feb 13, 2020 at 14:03
  • 1
    There is no mouse --wheel-lines=3 option ("less --help" for help)
    – alper
    Aug 27, 2020 at 21:20
  • @alper: That depends or which version of less you have I guess. My Arch installation supports that option
    – Raniz
    Aug 23, 2021 at 6:16
  • You probably need to upgrade your less for this flag to work (I had to). My system (MacOS 12.1) had less 487. Latest version is less 590. greenwoodsoftware.com/less
    – MEMark
    Feb 6, 2022 at 6:58
7

For those who are as a newbie like me, you have to enter the following to your terminal:

export LESS=-r

or use this:

export LESS=-R

you can use man less to see the difference

To have the effect persist, you can add this line to your ~/.bashrc and reopen your terminal.

0

I didn't know why, but unsetting this var does it. Other suggested answers however don't work.

unset LESS

less -V gives the following,

less 458 (POSIX regular expressions)
Copyright (C) 1984-2012 Mark Nudelman
1
  • 1
    You probably had some option already set then. What would echo $LESS give before unsetting it?
    – MEMark
    Feb 6, 2022 at 7:01

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .