Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Is there a straightforward way to adjust the colors used by vim and bash? Hex color values, for example?

share|improve this question
add comment

4 Answers

The colors used by bash are really actually used by the specific applications within bash. The colors used by LS can be changed by modifying the LSCOLORS variable. In your ~/.bashrc you would add something like:

export LSCOLORS=ehfacxdhbhegedabagacad
export GREP_COLOR='00;38;5;157;48;5;226'

etc...

VIM colors can be changed by simply specifying a theme.

share|improve this answer
1  
On my system it's LS_COLORS and the color specification is quite a bit different. (see man dircolors) –  Dennis Williamson Mar 23 '10 at 20:32
1  
This is a good point. On Macs and BSD systems, it will be LS_COLORS with a different syntax. –  moshen Mar 23 '10 at 21:56
add comment

vim supports colorschemes. You either use and/or install one of the many available schemes or write your own.

bash on the other hand is just a shell to execute programs. The display of the shell and its output is happening inside a terminal application that can support colors. If you e.g. use gnome-terminal you can modify the default colors used under Edit --> Profiles.

Many terminal applications can be configured to use colored instead of monochrome output, see e.g. moshen's answer.

share|improve this answer
    
Does cygwin have similar terminal settings? –  Nathan Long Mar 23 '10 at 19:23
add comment

There are a few things to get clear on here:

Bash is a shell, which itself is not so much where you want to manage color - that's more a matter of the terminal (gnome-terminal, rxvt, xterm, etc). Terminals typically either have 16, 88, or 256 color palettes, which are pre-defined colors it can render to the console. Each color has a number, from 0 to 15/87/255. Some terminals will let you adjust what specific RGB colors are assigned to which numbers, but typically its 0 for black, 1 for red, etc.

As for vim, do you mean vim, or gvim (the GUI application)? These are configured differently with respect to color. Vim allows you to change which of the available (numbered) terminal colors are assigned to which types of text (normal text, comment text, visually selected text, etc). Have a look at the vim help on the "colorscheme" and "highlight" commands. In terminal applications, you are confined to the colors available from your terminal (see above) but can assign them freely, defining your own color scheme.

Gvim, on the other hand, typically can let you specify RGB color triplets and thus have much more flexibility over your color scheme.

For example, in gvim, this will set your "normal" text color to an arbitrary hex RRGGBB triplet:

:hi Normal guifg=#123456

While in vim, this will set your "normal" text color to terminal color 1, which generally is red:

:hi Normal ctermfg=1

Your terminal application (xterm, gnome-terminal, rxvt) may then let you adjust what "red" really means, in terms of RGB. Some people, for instance find that the default "blue" in terminal applications is too dark to read, so adjust it to be brighter.

share|improve this answer
add comment

Another application which allows you to choose colors for its output is [less][1]. If it's the pager you use for man then these colors will most often be seen when you view man pages. You can see the meaning of the termcap codes such as "mr" (reverse video) and "md" (bold) by running man 5 terminfo and searching for the code. The color codes can be found in the "Color Handling" section of that man page.

Example settings:

LESS_TERMCAP_ZN=
LESS_TERMCAP_ZO=
LESS_TERMCAP_ZV=
LESS_TERMCAP_ZW=
LESS_TERMCAP_mb=$'\E[1m\E[38;5;2m'
LESS_TERMCAP_md=$'\E[1m\E[38;5;6m'
LESS_TERMCAP_me=$'\E[m\E(B'
LESS_TERMCAP_mh=
LESS_TERMCAP_mr=$'\E[7m'
LESS_TERMCAP_se=$'\E[27m\E[m\E(B'
LESS_TERMCAP_so=$'\E[1m\E[38;5;3m\E[48;5;4m'
LESS_TERMCAP_ue=$'\E[24m\E[m\E(B'
LESS_TERMCAP_us=$'\E[4m\E[1m\E[38;5;7m'
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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