5

To colorize my man pages, I put this code from archlinux.org into .bashrc:

man() {
    env LESS_TERMCAP_mb=$'\E[01;31m' \
    LESS_TERMCAP_md=$'\E[01;38;5;74m' \
    LESS_TERMCAP_me=$'\E[0m' \
    LESS_TERMCAP_se=$'\E[0m' \
    LESS_TERMCAP_so=$'\E[38;5;246m' \
    LESS_TERMCAP_ue=$'\E[0m' \
    LESS_TERMCAP_us=$'\E[04;38;5;146m' \
    man "$@"
}

It works okay, except when I search with /, the matches change colors to be even more obscure -- the opposite of highlighted. I spent some time trying to figure this out, but I can't really make sense of it, so if I do anything, it'll just be trial and error. Better to ask the experts. So how can I get search matches to be, say, black on yellow, please?

bongbang
  • 541

2 Answers2

5

Search patterns in less are colorize according to standout mode setting, so in order to display black on yellow you need to put

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

where 30 means black foreground, and 43 yellow background.

jimmij
  • 47,140
5

See man termcap for the full definition of the variables that you are exporting. For example, this excerpt covers starting and ending standout mode: the value that is used for highlighting searches:

se End standout mode
...
so Start standout mode

You can set yellow on a black background in your standout mode like so:

export LESS_TERMCAP_so=$'\E[01;33;03;40m'

It is worth noting that you don't need to export these variables in every shell, you can move this function to your ~/.profile or ~/.bash_profile to load them when you log in and they will persist.

jasonwryan
  • 73,126
  • Many thanks for the ~/.profile tip. – bongbang Nov 26 '14 at 00:05
  • Is this even correct: export LESS_TERMCAP_so=$'\E[01;33;03;40m', specifically the 03; portion? I see nothing about mode or color "03" in: man console_codes. – aDroid Mar 29 '19 at 20:10