Change less (pager) default options

9

3

I'm using Ubuntu 10.04. My default pager(set using update-alternatives, not $PAGER) is less. The problem is, when I use ri(Ruby documentation tool) with the '-f ansi' mode, less shows the escape sequences(such as 'ESC[36m') instead of displaying the text in color. I can force it to show colors by manually piping the output to less with the -R option, for example:

ri -f ansi String | less -R

However, I'd like this to be the default option when less is used as a pager.

Note: I'm aware that more and most show colors by default, but I use less because of the vi-like key bindings.

imgx64

Posted 2010-08-10T16:15:59.063

Reputation: 448

Answers

9

I found the answer somewhere else. I needed to use lesskey to set up less's options:

$ lesskey -
#env
LESS = -R

Then Ctrl+d

did the trick. I'm still not sure why less ignores $LESS though.

imgx64

Posted 2010-08-10T16:15:59.063

Reputation: 448

Aha! the options in ~/.less (which is what lesskey writes) override those in the environment. So you must have had a .less file containing LESS=-r before. – Gilles 'SO- stop being evil' – 2010-08-11T11:56:16.693

3

Set the LESS environment variable to a space-separated list of your favorite options.

Gilles 'SO- stop being evil'

Posted 2010-08-10T16:15:59.063

Reputation: 58 319

Didn't work, less totally ignores $LESS. I'm guessing this is an Ubuntu-specific issue, since many other shell variables are ignored, including $PAGER and $EDITOR. – imgx64 – 2010-08-11T05:15:52.147

less definitely takes $LESS into account, on Ubuntu 10.04 like everywhere else. And $PAGER and $EDITOR work too. It sounds like you're not setting the environment variables properly. How did you do it? – Gilles 'SO- stop being evil' – 2010-08-11T07:15:29.677

I tried this: "export LESS='-R'; ri -f ansi String | less"

However, less does use other environment variables correctly, such as the ones mentioned here: http://crunchbanglinux.org/forums/topic/2403/color-man-pages/

– imgx64 – 2010-08-11T10:01:19.563

@imgx64: It Works For Me™, and I don't see how it could not work. Hmmm... What is the output of the two commands type less and env | grep LESS? – Gilles 'SO- stop being evil' – 2010-08-11T10:25:07.517

"less is /usr/bin/less" and " LESS=-R LESSOPEN=| /usr/bin/lesspipe %s LESSCLOSE=/usr/bin/lesspipe %s %s " – imgx64 – 2010-08-11T11:06:10.327

1

The most likely issue is that you didn't export the less variable.

LESS="FRX"
ls -l | less
<not colorized>

export LESS="FRX"
ls -l | less
<colorized>

You could, for example, create a file called '/etc/profile.d/less.sh', with just 'export LESS="FRX"' in it, and your less configuration will be available system-wide.

Mr. B

Posted 2010-08-10T16:15:59.063

Reputation: 111

Yer no fun, slim. ..what's wrong with pointing out a bit of necromancy? – Mr. B – 2013-05-04T23:37:14.000