Make Less highlight search patterns instead of italicizing them

Found an answer over on the superuser: https://superuser.com/questions/566082/less-doesnt-highlight-search

Looks like it has to do with your TERM setting. For example, less highlighting acts normally (white background highlight) when in a normal gnome-terminal window, but when I'm in tmux, italics happens. The difference for me is that TERM is being set to "screen" when in tmux, but "xterm-256color" when not. When I set "TERM=xterm-256color" in the tmux window, highlighting in less goes back to background highlighting.


The mention of LESS_TERMCAP_so was incomplete. That is less's special environment variable used to override the termcap so (standout) capability. To use this capability, you have to provide a se (standend) capability as well.

The terminfo(5) manual page gives a summary of these features for terminfo (smso/rmso) and termcap (so/se) names:

   enter_standout_mode           smso       so        begin standout mode
   exit_standout_mode            rmso       se        exit standout mode  

Its section on highlighting explains:

If your terminal has one or more kinds of display attributes, these can be represented in a number of different ways. You should choose one display form as standout mode, representing a good, high contrast, easy-on-the-eyes, format for highlighting error messages and other attention getters. (If you have a choice, reverse video plus half-bright is good, or reverse video alone.) The sequences to enter and exit standout mode are given as smso and rmso, respectively.

If you want to use color for standout, you have to provide a corresponding LESS_TERMCAP_se which resets color. This is relatively simple to do as long as you do not expect to use colors in the manual page for other reasons (such as using groff's SGR color feature).

Assuming the value suggested in a comment:

export LESS_TERMCAP_so=$'\E[30;43m'

then you could reset that for most terminals using

export LESS_TERMCAP_se=$'\E[39;49m'

By the way, the reason for the italics is that the terminal description for GNU screen uses the standard escape sequence for italics as its own standout/standend capabilities. Some of that is discussed in the terminal database entry.


Hit ESCu to turn off search highlighting in less after a search; a new search will turn it on again, so to permanently turn search highlighting off for a session hit -G.

Alternately put LESS='-G' in your environment, or run man like so:

LESS='-G' man less

Ironically this is all documented in the less manpage...

You can also put the following in the environment, e.g. in your .bash_profile:

export MANPAGER='less -G'