1

This one beats me after 30 years of vi/vim usage... Context: I'm on FreeBSD using the latest vim (7.4.796). A month or so ago, syntax highlighting in xterm(318) started acting up. In particular, the highlighting of comments is cyan, not the expected gray.

To track this down I have done the following.

Strip down my ~/.vimrc to these few lines

$ vim .vimrc
  1 " Normal must be set before colors "fg" and "bg" can be used.
  2 highlight Normal ctermfg=216 ctermbg=233
  3
  4 " gray        This comment.
  5 highlight Comment   cterm=NONE      ctermfg=250     ctermbg=bg
  6
  7 " Line numbers indicate this .vimrc was read.
  8 set number
  9 syntax enable

Note that the line numbers appear; color 250 is gray in my TERM=xterm-256color.

I have moved away my ~/.vim directory to avoid any local plugin interference. Interestingly, when I :so .vimrc the correct color for the comments is used. It appears as if only the highlighting stuff is ignored upon startup, but works when sourced explicitly.

EDIT #1: I don't have any VIM environment variable set.

EDIT #2: :verbose hi Comment says

Comment        xxx term=bold ctermfg=14 guifg=#80a0ff
Last set from /usr/local/share/vim/vim74/syntax/syncolor.vim

EDIT #3: :scriptnames says

  1: ~/.vimrc
  2: /usr/local/share/vim/vim74/syntax/syntax.vim
  3: /usr/local/share/vim/vim74/syntax/synload.vim
  4: /usr/local/share/vim/vim74/syntax/syncolor.vim
  5: /usr/local/share/vim/vim74/filetype.vim
  6: /usr/local/share/vim/vim74/plugin/getscriptPlugin.vim
  7: /usr/local/share/vim/vim74/plugin/gzip.vim
  8: /usr/local/share/vim/vim74/plugin/logiPat.vim
  9: /usr/local/share/vim/vim74/plugin/matchparen.vim
 10: /usr/local/share/vim/vim74/plugin/netrwPlugin.vim
 11: /usr/local/share/vim/vim74/plugin/rrhelper.vim
 12: /usr/local/share/vim/vim74/plugin/spellfile.vim
 13: /usr/local/share/vim/vim74/plugin/tarPlugin.vim
 14: /usr/local/share/vim/vim74/plugin/tohtml.vim
 15: /usr/local/share/vim/vim74/plugin/vimballPlugin.vim
 16: /usr/local/share/vim/vim74/plugin/zipPlugin.vim

Now I ran out of ideas what is going on here and how to fix it. Someone hit me with the clue bat, please.

  • 3
    Does the order have anything to say? That is, what if you move the highlight commands to the bottom of the vimrc file? – Karl Yngve Lervåg Jul 27 '15 at 20:16
  • @KarlYngveLervåg No, that doesn't change anything. – Jens Jul 27 '15 at 21:08
  • 1
    After starting Vim, what does :verbose hi Comment tell you? – jjaderberg Jul 27 '15 at 21:16
  • @jjaderberg :verbose hi Comment Comment xxx term=bold ctermfg=14 guifg=#80a0ff Last set from /usr/local/share/vim/vim74/syntax/syncolor.vim – Jens Jul 27 '15 at 21:20
  • Is it perhaps this issue? – Martin Tournoij Jul 27 '15 at 21:25
5

Patches 7.4.757 on June 25, 7.4.766 on July 3, and 7.4.770 on July 10 added a feature to Vim in terminal mode that queries the terminal for its background color using the T_RGB escape sequence. When Vim receives the background color response from the terminal and the received background is different from the default (light), Vim changes the highlight colors to be compatible with the new background.

A little testing verifies that Vim 7.4.729 running in xterm 318 starts with 'background' = light, but Vim 7.4.797 automatically sets 'background' = dark.

A solution is to put

set background=light

in your ~/.vimrc. I think that setting this tells Vim not to query the terminal. It may just tell Vim to ignore the terminal's response to the background color query.

You can find out a little about the effect of setting 'background' from

:help 'background'

but I haven't found any documentation on this automatic setting feature.

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.