Set background and hi Normal: in which order?

115 views
Skip to first unread message

Lifepillar

unread,
Aug 12, 2018, 10:58:59 AM8/12/18
to vim...@googlegroups.com
Dear masters of Vim colorschemes,
which of the following should a dark-only colorscheme use?

(1)
set background=dark
hi Normal ...
" Other highlight groups here

(2)

hi Normal ...
set background=dark
" Other highlight groups here

(3)
hi Normal ...
" Don't set 'background' at all.
" Other highlight groups here

I am asking because I have always used (1), but recently I have found
an instance (iVim for iOS, which is based on Vim 7.4.900) in which my
colorscheme has the wrong color for the status line. The relevant part
of the highlight group is defined as follows (below you find the full
definition):

hi StatusLine guifg=#64878f guibg=fg gui=NONE,reverse

At startup, the foreground color of the status line is set to Normal
background (#292c36) instead of Normal foreground (#ffffff). Reloading
the colorscheme is necessary to get the right color.

Either setting the background *after* defining the Normal hi group or
relying on Vim to set the background correctly fixes the issue. So,
now I am leaning towards using (2) as a more robust choice, but you
know better.

So, what is the "best practice" here: (1), (2), or (3)?

Thanks,
Life.


Full example:

set background=dark

hi clear
if exists('syntax_on')
syntax reset
endif

let g:colors_name = 'test'

hi Normal ctermfg=15 ctermbg=0 guifg=#ffffff guibg=#292c36
\ guisp=NONE cterm=NONE gui=NONE
hi StatusLine ctermfg=6 ctermbg=15 guifg=#64878f guibg=fg
\ guisp=NONE cterm=NONE,reverse gui=NONE,reverse



Tony Mechelynck

unread,
Aug 12, 2018, 11:39:20 AM8/12/18
to vim...@googlegroups.com
On Sun, Aug 12, 2018 at 4:58 PM, Lifepillar <lifep...@lifepillar.me> wrote:
> Dear masters of Vim colorschemes,
> which of the following should a dark-only colorscheme use?
>
> (1)
> set background=dark
> hi Normal ...
> " Other highlight groups here
>
> (2)
>
> hi Normal ...
> set background=dark
> " Other highlight groups here
>
> (3)
> hi Normal ...
> " Don't set 'background' at all.
> " Other highlight groups here
>
> I am asking because I have always used (1), but recently I have found
> an instance (iVim for iOS, which is based on Vim 7.4.900) in which my
> colorscheme has the wrong color for the status line. The relevant part
> of the highlight group is defined as follows (below you find the full
> definition):
>
> hi StatusLine guifg=#64878f guibg=fg gui=NONE,reverse
>

I may be wrong but I _think_ that setting gui=NONE clears (i.e. makes
irrelevant) the guifg= guibg= settings which come before. I would then
expect the above to set the StatusLine background to Normal foreground
and vice-versa.

If you want the Normal group to be set to bg=#64878f fg=#ffffff I
would rather write

hi StatusLine guibg=#64878f guifg=white

which seems simplest (and clearest) to me. (I would regard it as
pathological not to set the "white" colour to #FFFFFF.) Or if you want
the StatusLine highlight to be the exact reverse of the Normal
highlight (i.e. bg = Normal fg, fg = Normal bg) then use

hi StatusLine gui=NONE,reverse

without the guibg= guifg= which clutter your definition above.

> At startup, the foreground color of the status line is set to Normal
> background (#292c36) instead of Normal foreground (#ffffff). Reloading
> the colorscheme is necessary to get the right color.
>
> Either setting the background *after* defining the Normal hi group or
> relying on Vim to set the background correctly fixes the issue. So,
> now I am leaning towards using (2) as a more robust choice, but you
> know better.
>
> So, what is the "best practice" here: (1), (2), or (3)?
>
> Thanks,
> Life.
>
>
> Full example:
>
> set background=dark
>
> hi clear
> if exists('syntax_on')
> syntax reset
> endif
>
> let g:colors_name = 'test'
>
> hi Normal ctermfg=15 ctermbg=0 guifg=#ffffff guibg=#292c36
> \ guisp=NONE cterm=NONE gui=NONE
> hi StatusLine ctermfg=6 ctermbg=15 guifg=#64878f guibg=fg
> \ guisp=NONE cterm=NONE,reverse gui=NONE,reverse
>

Best regards,
Tony.

Lifepillar

unread,
Aug 12, 2018, 12:34:01 PM8/12/18
to vim...@googlegroups.com
On 12/08/2018 18:39, Tony Mechelynck wrote:
> On Sun, Aug 12, 2018 at 4:58 PM, Lifepillar <lifep...@lifepillar.me> wrote:
>> Dear masters of Vim colorschemes,
>> which of the following should a dark-only colorscheme use?
>>
>> (1)
>> set background=dark
>> hi Normal ...
>> " Other highlight groups here
>>
>> (2)
>>
>> hi Normal ...
>> set background=dark
>> " Other highlight groups here
>>
>> (3)
>> hi Normal ...
>> " Don't set 'background' at all.
>> " Other highlight groups here
>>
>> I am asking because I have always used (1), but recently I have found
>> an instance (iVim for iOS, which is based on Vim 7.4.900) in which my
>> colorscheme has the wrong color for the status line. The relevant part
>> of the highlight group is defined as follows (below you find the full
>> definition):
>>
>> hi StatusLine guifg=#64878f guibg=fg gui=NONE,reverse
>>
>
> I may be wrong but I _think_ that setting gui=NONE clears (i.e. makes
> irrelevant) the guifg= guibg= settings which come before.

I have never seen it work that way. Anyway, nothing of what I have
described changes if you use gui=reverse instead of gui=NONE,reverse.

> If you want the Normal group to be set to bg=#64878f fg=#ffffff I
> would rather write
>
> hi StatusLine guibg=#64878f guifg=white
>
> which seems simplest (and clearest) to me.

Fine, but my question is different: is it true that (1), (2) and (3)
above always produce the same result? I used to think that the answer
was positive, at least for (1) and (2), but I have encountered a case
(using fg in iVim) in which there is a difference between (1) and (2).

Also, in a very old thread entitled "[BUG] Background is reset when
ctermbg for `Normal' group is redefined", Bram wrote the following
reply:

>You would normally first set the Normal
>highlighting, and if the 'background' option is then wrong correct it.
>Then set the other colors.

which makes me believe that (2) is the way to go. But that was in 2006,
and I don't know whether the advice is still valid.

Life.

Reply all
Reply to author
Forward
0 new messages