5

I am a bit lost here on customizing the search/find highlight color or font format if you will. I understand that using LESS_TERMCAP_* we can alter the font format of less display. Full capabilities are here.

But I couldn't get how to change the search highlight! I want to add background color and change fore color to make them different from the standard output colors. Negating the standard output is preferred.

Also, one more question. A parameter with special characters (like @0), how can we write their LESS_TERMCAP_ variable?

It's getting really annoying not being able to even guess which one to use to change the colors! Thanks in advance for shedding some light on the matter.

  • 1
    It is LESS_TERMCAP_so. – jimmij Jan 9 '18 at 13:44
  • Working! Thanks. But how can I able to tell without asking every time I want to know which key to use? – joker Jan 9 '18 at 13:57
  • It is not well documented, you need to read sources, or just experiment a bit. There are only 4 capabilities supported in less: _so(standout), _mb(blinking), _md(bold) and _us(underline), so not much to experiment with. – jimmij Jan 9 '18 at 14:03
0

There is a list of different termcaps global variables that are read by less; the relevant ones are found in the code as:

tmodes("so", "se", &sc_s_in, &sc_s_out, "", "", &sp);
tmodes("us", "ue", &sc_u_in, &sc_u_out, sc_s_in, sc_s_out, &sp);
tmodes("md", "me", &sc_b_in, &sc_b_out, sc_s_in, sc_s_out, &sp);
tmodes("mb", "me", &sc_bl_in, &sc_bl_out, sc_s_in, sc_s_out, &sp);

The tmodes function prefixes its first two arguments with LESS_TERMCAP_ and uses the value of the env variable with that name for, as described by user jimmij:

  • so standout, se exit standout,
  • us underline, ue exit underline,
  • md bold, me exit underline,
  • mb blinking, me exit blinking (and underline).

You can have your matches appearing in red using:

$ export LESS_TERMCAP_so=$(echo -e '\e[1;91m')
$ export LESS_TERMCAP_se=$(echo -e '\e[0m')

See this Wikipedia page for more on ANSI escape sequences (including background coloring, bold, ...).

It's worth noting that less reads much more LESS_TERMCAP_* variables than just these (for keys, for instance).

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.