Customize man page colors with ‘less’ definitions

Man pages by default use less for displaying. I’ve used vim before to for colored text in man pages but something got bjorked in an update. To have color with man pages termcap will need to be invoked. Thanks to nico for the tip.

All that needs to be done is to export bold and underline values of termcap. Adding the values to the ~/.bashrc will make sure that they are always used:

# Less Colors for Man Pages
export LESS_TERMCAP_mb=$'\E[01;31m'       # begin blinking
export LESS_TERMCAP_md=$'\E[01;38;5;74m'  # begin bold
export LESS_TERMCAP_me=$'\E[0m'           # end mode
export LESS_TERMCAP_se=$'\E[0m'           # end standout-mode
export LESS_TERMCAP_so=$'\E[38;5;246m'    # begin standout-mode - info box
export LESS_TERMCAP_ue=$'\E[0m'           # end underline
export LESS_TERMCAP_us=$'\E[04;38;5;146m' # begin underline

And source the ~/.bashrc to have it work:

source ~/.bashrc

Notice I used Arch and Gentoo colors, my two favorite distros :) :

About Gen2ly

<3's linux

Posted on 2009-03-23, in Command Line, Configuration, Linux. Bookmark the permalink. 39 Comments.

  1. What I’d be inerested even more is syntax highlighting in ‘less’ …is that possible or should I just use ‘vim’ as my viewer as well?

  2. Unsure. But termcap is limited and i dont’ think it has the ability to ‘recognize strings’ only predefined variables (like man-pages got). You can look at ‘man termcap’ to what it can do. A wrapper script possibly could be put around it but i think that would be alot, alot of work.

  3. Do you use xterm? Something must be interfering with mine in my environment as it is not trivial to get it working on my host.

  4. Jeremy, most do use Xterm. If it is not working on your terminal, it be best to provide more Details.

  5. Ahh, this is quite concerning and probably the source of the issue:

    %% env|grep LESS_TERMCAP

    any ideas?

  6. Same here Jeremy. Not sure of the problem yet myself….

  7. Hmm, this is a bit out there but I notice most people use \e to begin escape sequences before entering terminal colors. Possible try this?

  8. Those variables only *appear* to be emtpy, because they are entirely made of unprintable escape sequences.

    Try: env | grep LESS_TERMCAP | cat

    You still won’t see the codes, but you see the effect on the next line that’s printed out.

  9. Nice tip, works fine for me.
    I am interested in the colors though, cause i am on Arch :)
    Do you happen to have a corresponding (read: equally nice) color theme for your xterm and maybe vim ?


  10. That’s a bit in deliberation. I using yakuake, and using a theme based on Konsole, Oxygen theme:

    The values I’m using:

    color0 181C20 color1 A44245 color2 00BF00 color3 BBAD5B color4 2B76C7 color5 8B56A3 color6 5BCEE4 color7 D4D7D0 color8 A44245 color9 A44245 color10 37A42B color11 C4C29B color12 2B76C7 color13 8B56A3 color14 71AAB3 color15 EAEAEA

    As for vim there’s alot to choose but I like how the Oxygen scheme looks in it. For more basic tones you might want to look at brian’s Gentooish vim scheme though:

  11. Very nice tip, thanks! Works really good : )

  12. for mac os x this is what i had to use, as it appears a less advanced ansi color interpretation:

    export LESS_TERMCAP_mb=$’\E[01;31m’ # begin blinking
    export LESS_TERMCAP_md=$’\E[01;31m’ # begin bold
    export LESS_TERMCAP_me=$’\E[0m’ # end mode
    export LESS_TERMCAP_se=$’\E[0m’ # end standout-mode
    export LESS_TERMCAP_so=$’\E[01;44m’ # begin standout-mode – info
    export LESS_TERMCAP_ue=$’\E[0m’ # end underline
    export LESS_TERMCAP_us=$’\E[32m’ # begin underline

  13. Mark Nudelman

    I see a few issues with this approach. If you login to your account from different terminals, the same escape sequences will be sent in all cases. There’s no way to personalize this for different terminals. (Also, it uses an undocumented feature of less, which may change or disappear. These LESS_TERMCAP_xxx environment variables were intended to make it easy to cause escape sequences to become visible, to aid in debugging.)

    I think a better approach is to personalize your termcap/terminfo database. On a Fedora systems, for example, I can do

    echo ‘xterm-mycolors, bold=\E[38;5;246m, sgr0=\E[0m, use=xterm,’ >myterm.ti

    tic myterm.ti

    export TERM=xterm-mycolors

    This not only achieves the same thing in less without using undocumented features, it makes bold text be the desired color in all programs that use termcap/terminfo.


  14. Juan Sinpelo

    There is no need to use most, it can also be done with most :-)

  15. Someone necessarily assist to make seriously
    posts I might state. That is the very first time I frequented your web page and so
    far? I amazed with the analysis you made to create this actual post
    amazing. Fantastic task!

  16. It’s awesome to visit this web page and reading the views of all mates about this piece of writing, while I am also eager of getting experience.

  17. Hello, yeah this article is genuinely good and I have learned lot of
    things from it about blogging. thanks.

  18. This includes emotional abuse, physical abuse as well as sexual abuse.
    John’s Wort which helps to provide anxiety relief and controls and lessens panic attack occurrence. The sudden onset of this symptom can certainly lead a person to feel as if they are suffering a heart attack.

  19. Power stations would have to be built every 2 miles along the
    power lines. Luckily, several pioneers have worked hard and collaborated on Tesla’s work over the years.
    The mans name is Marin Soljacic, a professor at MIT
    and founder of one of the leading companies in our electronic future, Witricity.

  20. To see the normally-invisible escape sequences in the LESS_TERMCAP_* variables, try `cat -v`:

    $ env | grep ^LESS_TERMCAP | cat -v

    You can also use less itself, as long as its ‘raw control chars’ mode is disabled, i.e. `env | grep ^LESS_TERMCAP | less -+r`.

  21. You can perform stomach fat exercises early inside morning or perhaps at evening after school or work.
    At you’ll find the best number of vacuum packing machines, suitable for both domestic and commercial needs.

    The vacuum packing machine removes your entire oxygen from the system,
    in order that it relieves the foodstuff from any oxidation and therefore, prevents lack of shape or flavour.

    Too much heat may make the meal too hard around the outside while still
    remaining moist for the inside. she says

  22. Over a 3rd of these that carry the herpes simplex virus
    will never get yourself a wintry sore or fever blister.

  23. Thanks for some other informative blog. The place else may I get that type
    of info written in such an ideal way? I’ve a project that I’m just now working
    on, and I’ve been on the glance out for such info.

  24. I know this web site presents quality based articles
    and other stuff, is there any other web page which presents such information in quality?

  25. Just want to say your article is as surprising.
    The clearness to your publish is simply spectacular and i can assume you’re a professional on this
    subject. Fine with your permission let me to
    take hold of your RSS feed to stay updated
    with impending post. Thank you 1,000,000 and please carry
    on the enjoyable work.

  26. Hello my loved one! I want to say that this post is awesome, great written and come with approximately
    all important infos. I would like to peer more posts like this

  27. Great blog right here! Additionally your site rather a lot up fast!

    What web host are you the use of? Can I get your affiliate link to your host?

    I want my site loaded up as quickly as yours lol

  28. For instance, in case you’re purchasing rain boots,
    chances are you’ll now select many options, and this also
    could get confusing. Almost all today’s women’s rubber rain boots come that has a specially designed tread to counteract falls.
    Ilse jacobsen If you’ll need protection through the snow likewise then you might want to think
    about a lined set of two boots in whatever style
    you ultimately choose.

    Not only are these rain boots an easy task to pull on and lose, they will also be equipped with rubber outsole pods offering extra
    traction on slippery surfaces. Once you start proper dog training, you must ensure that everyone inside house provides consistent commands.

  1. Pingback: Color man pages : Linux T&T

  2. Pingback: code(alpha) » Colored Man Pages

  3. Pingback: S03E20 – The Midnight Flyer – MP3 LOW | Ubuntu Podcast from the UK LoCo team

  4. Pingback: S03E20 – The Midnight Flyer – MP3 HIGH | Ubuntu Podcast from the UK LoCo team

  5. Pingback: S03E20 – The Midnight Flyer – OGG HIGH | Ubuntu Podcast from the UK LoCo team

  6. Pingback: S03E20 – The Midnight Flyer | Ubuntu Podcast from the UK LoCo team

  7. Pingback: S03E20 – The Midnight Flyer – OGG LOW | Ubuntu Podcast from the UK LoCo team

  8. Pingback: What viewer to use for viewing man pages with syntax highlighting?

  9. Pingback: Different color prompts for different machines when using terminal/ssh? - Question Lounge

  10. Pingback: colour man pages - jonathans blog

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


Get every new post delivered to your Inbox.

Join 58 other followers

%d bloggers like this: