5

For readability I try to modify my ~/.vimrc to get some proper highlighting. I found here to use e.g. this:

highlight DiffChange cterm=none ctermfg=fg ctermbg=Red gui=none guifg=fg guibg=Red

Like said in the link I am getting following warning then: E419: FG color unknown

I don't really understand the suggestion to use

highlight Normal term=none cterm=none ctermfg=White ctermbg=Black gui=none guifg=White guibg=Black

to get rid of that problem but it works. Still all text in vim is written bold (highlighted) afterwards. How do I get rid of this? Or is there a better/simpler possibilty to manipulate the highlighting colors?

7

You have a few questions, some explicit and some implicit. I'll try to answer them in order:

What Do These Commands Do?

You're running two commands:

highlight DiffChange cterm=none ctermfg=fg ctermbg=Red gui=none guifg=fg guibg=Red

highlight Normal term=none cterm=none ctermfg=White ctermbg=Black gui=none guifg=White guibg=Black

Both of these commands set the colors of highlight groups. A highlight group is how Vim sets the color (and formatting) of an element of the text or editor. The various variables you're setting (ctermbg=Red for example) are how you tell Vim what colors and formatting you'd like. The variables that end in fg set the foreground (text) color, the variables that end in bg set the background color, and the variables without a suffix (term, cterm, gui) set the formatting (like Bold, or Underline, etc.). You can find the list of formatting options with :h highlight-term.

In this case you set the color of the DiffChange group and the Normal group.

You can get help on these like this: :h hl-DiffChange and :h hl-Normal

The DiffChange group tells Vim how to highlight lines that have changed in the diff, while the Normal group sets the color of normal text and the background of the editor.

So putting it together you're telling vim I would like white text on a black background, and when I do a diff, I would like you to keep the text color (the foreground) the same color as it is normally (this is what fg means, will discuss that in the next section) and change the background to Red.

Why Doesn't fg Work Initially?

Vim has a few color names that it knows, like White, Black, etc. Some of them (the ones understood by the color terminal) are listed with :h cterm-colors:

                        *cterm-colors*
    NR-16   NR-8    COLOR NAME
    0       0       Black
    1       4       DarkBlue
    2       2       DarkGreen
    3       6       DarkCyan
    4       1       DarkRed
    5       5       DarkMagenta
    6       3       Brown, DarkYellow
    7       7       LightGray, LightGrey, Gray, Grey
    8       0*      DarkGray, DarkGrey
    9       4*      Blue, LightBlue
    10      2*      Green, LightGreen
    11      6*      Cyan, LightCyan
    12      1*      Red, LightRed
    13      5*      Magenta, LightMagenta
    14      3*      Yellow, LightYellow
    15      7*      White

Additionally, there are the 'special' fg and bg colors that reference the color of the text and the background. Vim gets the colors for these from the normal highlight group. The vim help has this to say about them:

                        *E419* *E420*
When Vim knows the normal foreground and background colors, "fg" and
"bg" can be used as color names.  This only works after setting the
colors for the Normal group and for the MS-DOS console.  Example, for
reverse video: 
    :highlight Visual ctermfg=bg ctermbg=fg
Note that the colors are used that are valid at the moment this
command are given.  If the Normal group colors are changed later, the
"fg" and "bg" colors will not be adjusted.

The command that you use, highlight Normal term=none cterm=none ctermfg=White ctermbg=Black gui=none guifg=White guibg=Black, sets the colors for the Normal group to Black for the backgrounds of the color terminal (ctermbg) and GUI (guibg) and White for the foregrounds (main text color) for the color terminal (ctermfg) and the GUI (guifg). After setting that, Vim knows that fg is White and bg is Black, but before it doesn't and so you can't use fg.

Why Is All The Text Bold?

This is likely a problem with your terminal and not with Vim. If Vim thinks your terminal can only display 8 colors, than all text will be bold. You should make sure your $TERM variable in your terminal is set correctly. The exact way to do this depends on your shell, but if for example you're using bash in xterm, its likely your terminal is reporting TERM="xterm", when it should be TERM="xterm-256color" if it supports 256 colors (and it should if its a modern version). Some information on this can be found on the vim wikia.

You can check the number of colors vim thinks it can use with :set t_Co?. If this reports 8 or lower than that is probably your problem. Fixing $TERM is the right solution, but a hack is to override t_Co in your .vimrc: set t_Co=256.

If you let us know what terminal and shell you're running, I can offer more specific advice.

Is There a Better/Simpler Way?

Setting highlight groups in vim is just messy and ugly. Some people have written plugins or scripts to make it "easier" or "cleaner" (for example EasyColour, or this vimscript function), but whether those are preferable is really a personal decision.

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.