Change less (pager) default options

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.


Solution 1:

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.

Solution 2:

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

Solution 3:

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.