Sunday, August 12, 2018

Re: Set background and hi Normal: in which order?

On Sun, Aug 12, 2018 at 4:58 PM, Lifepillar <lifepillar@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.

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments: