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?

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.

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.

  • Many thanks for the ~/.profile tip. – bongbang Nov 26 '14 at 0: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 at 20:10

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.