Tuesday, May 9, 2017

Re: Please explain highlight groups User1 ... User9!!!

On Tuesday, May 9, 2017 at 8:31:12 PM UTC-4, Tony Mechelynck wrote:
> On Wed, May 10, 2017 at 12:59 AM, <jrfranklin@georgiasouthern.edu> wrote:
> > Hello All,
> >
> > I've been trying to master my statusline customizations, and I've hit a wall in the application of colors to the statusline.
> >
> > The documentation suggests to use the User1 to User9 highlight groups. Quoting from ":h 'statusline'":
> >
> > > * - Set highlight group to User{N}, where {N} is taken from the
> > > minwid field, e.g. %1*. Restore normal highlight with %* or %0*.
> > > The difference between User{N} and StatusLine will be applied
> > > to StatusLineNC for the statusline of non-current windows.
> > > The number N must be between 1 and 9. See |hl-User1..9|
> >
> > This just seems cryptic to me. When I define User1 with the ":highlight" command, I would expect Vim to automatically adjust my highlighting to indicate an inactive window (based on the statements above). However, in Vim 7.4, the highlighting is the same for all windows. I use GVim 8 at work, and the colors appear to adjust, but I'm just not sure that I'm even using the feature correctly.
> >
> > Should I expect automatic adjustment of my User1 color in the statusline (using the "%*1" format spec)?
> >
> > I'm tremendously confused about this feature and would love nothing more than to feel once-again in control of my statusline!!!
> >
> > Thanks to all!
> > Jason
>
> Highlight groups (all of them) are indeed global. Using the :hi
> command with no arguments displays them all — there are a lot of them.
> You may change them depending on context by *carefully* setting
> autocommands in your owncoded colorscheme. Here is an example from
> mine, sorry if it may seem longish. The autocommands are at the end
> but they use what comes above it. Notice the "uninstall" autocommand
> at the bottom for when the user sets a different colorscheme.
> (g:CSApprox_approximator_function is a Funcref defined by the CSApprox
> plugin.)
>
> " display the status line of the active window in a distinctive color:
> " bold black on bright red in the GUI, white on green in the console
> " (where the bg is never bright, and dark red is sometimes an ugly sort
> " of reddish brown).
> hi StatusLine gui=NONE,bold guibg=red guifg=black
> \ cterm=NONE,bold ctermbg=darkgreen ctermfg=white
> hi WildMenu gui=NONE,bold guibg=#00FF00 guifg=black
> \ cterm=NONE,bold ctermbg=black ctermfg=white
> " make the status line bold-reverse (but B&W) for inactive windows
> hi StatusLineNC gui=reverse,bold
> \ cterm=NONE ctermbg=black ctermfg=lightgrey
> " make the active status line colours alternate between two settings
> " to give a visual notice of the CursorHold/CursorHoldI events
> if ! exists("s:statuslineflag")
> let s:statuslineflag = 0
> endif
> "
> " The following 'fancy footwork' is needed to have our CursorHold autocommand
> " work smoothly with 256-color cterms handled by the 3rd-party
> csapprox.vim plugin
> if exists('g:CSApprox_approximator_function')
> let s:ctbg1 = g:CSApprox_approximator_function(0, 255, 0) " green
> let s:ctbg2 = g:CSApprox_approximator_function(255, 0, 0) " red
> let s:ctfg = g:CSApprox_approximator_function(0, 0, 0) " black
> else
> let s:ctbg1 = 'darkgreen'
> let s:ctbg2 = 'black'
> let s:ctfg = 'white'
> endif
>
> function! ToggleStatusLine()
> if s:statuslineflag
> exe 'hi StatusLine'
> \ 'cterm=NONE,bold ctermbg=' . s:ctbg1 'ctermfg=' . s:ctfg
> \ 'gui=NONE,bold guibg=#00FF00 guifg=black'
> exe 'hi WildMenu'
> \ 'cterm=NONE,bold ctermbg=' . s:ctbg2 'ctermfg=' . s:ctfg
> \ 'gui=NONE,bold guibg=red guifg=black'
> else
> exe 'hi StatusLine'
> \ 'cterm=NONE,bold ctermbg=' . s:ctbg2 'ctermfg=' . s:ctfg
> \ 'gui=NONE,bold guibg=red guifg=black'
> exe 'hi WildMenu'
> \ 'cterm=NONE,bold ctermbg=' . s:ctbg1 'ctermfg=' . s:ctfg
> \ 'gui=NONE,bold guibg=#00FF00 guifg=black'
> endif
> let s:statuslineflag = ! s:statuslineflag
> endfunction
>
> exe "augroup" s:colors_name
> au! CursorHold,CursorHoldI * call ToggleStatusLine()
> au! ColorScheme *
> \ if g:colors_name != s:colors_name | exe "au!" s:colors_name | endif
> augroup END


Thanks a ton for the reply, Tony!

So, just to confirm: There is NO WAY to conveniently specify a pair of colors that the status line will use to alternate between to indicate active/inactive status? I find that hard to believe. This seems extremely odd to me if it's the case. In fact, it would appear to be a deficiency within Vim itself.

As another follow up question regarding the documentation: Note that it says "the difference ... will be applied". This seems to indicate that vim should automatically "darken" inactive windows for me when I've defined and used User1 to highlight my statusline. The documentation is then poorly written if this is not the behavior. In fact, I have no idea what it means... Any thoughts?

Thanks again for the reply, man!

--
--
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: