Wednesday, May 10, 2017

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

On Wednesday, May 10, 2017 at 9:37:41 AM UTC-4, Tony Mechelynck wrote:
> On Wed, May 10, 2017 at 6:09 AM, <jrfranklin@georgiasouthern.edu> wrote:
> > On Tuesday, May 9, 2017 at 11:35:47 PM UTC-4, Tony Mechelynck wrote:
> >> On Wed, May 10, 2017 at 3:04 AM, <jrfranklin@georgiasouthern.edu> wrote:
> >> [...]
> >> > 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!
> >>
> >> The status line for the current split-window is highlighted in the
> >> StatusLine highlight group. Status lines for all other split-windows
> >> (the inactive ones) are highlighted in the StatusLineNC highlight
> >> group. In addition, when doing command-line completion, the currently
> >> selected match is highlighted in the WildMenu highlight group. These
> >> are used on the default status lines and if you don't specify special
> >> highlighting they will be used in custom status lines too.
> >>
> >> Anything that can be tested fom the context of a split-window can be
> >> used to set a different highlight to part of the status line. The
> >> colours themselves are global, but by using appropriate constructs in
> >> your 'statusline' option you can build it with almost infinite
> >> variety. if?then:else expressions can be used advantageously there to
> >> put various text, and even various highlight groups, depending on
> >> circumstances; and any highlight groups can be used: "User" groups by
> >> using %1* to %9* and any other ones by using their name, e.g. (IIUC,
> >> and including the option-backslashes to guard the double quotes)
> >> %{&binary?\"%#Error#BINARY%0*\":\"\"} to output the text BINARY in the
> >> scary Error highlight group at that point of the statusline for
> >> windows displaying buffers where the 'binary' local option is set.
> >>
> >> See
> >> :h 'statusline'
> >> :h option-backslash
> >>
> >> P.S. Here's how I set my status line. Rather complicated but I like the result:
> >>
> >> if has('statusline')
> >> set statusline=%<%f\
> >> %h%m%r%=%k[%{(&fenc==''?&enc:&fenc)}%{(&bomb?',BOM':'')}][U+%04B]\
> >> %-12.(%l,%c%V%)\ %P
> >> endif
> >>
> >> and here is how I set my text-style tab bar (even in gvim, using
> >> 'showtabline' set to 2 and e absent from 'guioptions') with fancy
> >> colors (the principle is the same as for the status line but I use a
> >> function to construct it in steps):
> >>
> >> if has('windows') && exists('+tabline')
> >> function MyTabLine()
> >> let rv = ''
> >> let i = 1
> >> while i <= tabpagenr('$')
> >> let rv .= '%#Normal#'
> >> let icur = tabpagewinnr(i)
> >> let imax = tabpagewinnr(i, '$')
> >> let rv .= '%' . i . 'T'
> >> let rv .= i . '|' . icur . ':' . imax . ' '
> >> if i == tabpagenr()
> >> let rv .= '%#NonText#'
> >> else
> >> let rv .= '%#SpecialKey#'
> >> endif
> >> let buf = fnamemodify(bufname(tabpagebuflist(i)[icur-1]),':t')
> >> if buf == ""
> >> let buf = '[NoName]'
> >> endif
> >> let rv .= buf . ' '
> >> let i += 1
> >> endwhile
> >> let rv .= '%T%=%999X%#Error#X%#Normal#%X'
> >> return rv
> >> endfunction
> >> set tabline=%!MyTabLine()
> >> set showtabline=2
> >> endif
> >>
> >> Best regards,
> >> Tony.
> >
> > Tony,
> >
> > Thanks again for your efforts.
> >
> > The code you posted is broken, I'm afraid. In particular, the following example
> >
> > > %{&binary?\"%#Error#BINARY%0*\":\"\"} to output the text BINARY in the
> >
> > does not work as you might expect. This has caused me much grief in the past couple of weeks of looking for a solution to my problem. It is not possible to nest highlight group items within expression items. I certainly wish it were! That would solve ALL of my problems!
> >
> > The definition of my statusline can be found here: https://github.com/lifecrisis/vim-vimrc/blob/master/vimrc#L434.
> >
> > I want to emphasize that I think the documentation here is wrong. To quote again:
> >
> > > * - 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 indicates clearly that there should be some kind of automatic behavior in relation to the User1...User9 highlight groups. The whole "difference between" nonsense... what on Earth is that??? That clearly indicates that some kind of automatic action should be taken by Vim... LOL I'm about to pull my hair out! HAHA!
> >
> > There MUST be an elegant and concise way to highlight the statusline that automatically "darkens" the statuslines in the inactive windows.
>
> Yes, there is. Just don't set any highlight group in your statusline,
> and set constrastive colours to the StatusLine and StatusLineNC
> highlight groups. Normally this is best done in a colourscheme. If
> these two groups are set to the same colours, Vim will add circumflex
> accents ^^^^^^^ in the empty spaces of the current window's statusline
> instead.
>
> See
> :help hl-StatusLine
> :help hl-StatusLineNC
> >
> > I'm lost for where to look...
> >
> > Thanks again!
> > Jason
>
> Best regards,
> Tony.
>
> P.S. I'm attaching my own "almost-default" colorscheme. To use it,
> drop it in one of the following directories (I'm listing them using
> the Unix-like notation used in Vim; for Windows, use %VARIABLE%
> instead of $VARIABLE and \ instead of / when working outside Vim):
>
> $VIM/vimfiles/colors/ (system-wide, for any OS)
> $HOME/.vim/colors/ (user-private, for Unix-like OSes
> including Linux and Mac OS X)
> $HOME/vimfiles/colors/ (user-private, for Windows)
>
> ...then use the ":colorscheme almost-default" command (without the
> quotes), either by typing it manually to try it out, or in your vimrc
> if you like it. It is meant for gvim, for a 24-bit-color console with
> 'termguicolors' set, or for an 88- or 216-color console with 't_Co'
> set appropriately and the CSApprox plugin installed; but it will work
> even in an 8-background, 16-foreground color terminal (and display
> fewer colours there, of course).

Hey Tony,

I understand the default behavior of the highlight groups StatusLine and StatusLineNC. That is not the issue. The problem is that grouping items in the statusline by color is brittle because one cannot conditionally apply colors in the statusline and have an automatic darkening effect as you would expect.

In short, putting more than two colors in your statusline requires all kinds of special hacks to get the "darkening" effect to work. It is then not guaranteed to work, for example if some other script ever uses the 'eventignore' setting. This is painful if you just want an attractive statusline that works seamlessly.

> %{&binary?\"%#Error#BINARY%0*\":\"\"} to output the text BINARY in the

The conditional application of highlighting that you mentioned above is what I want, but it does not work. The documentation here is incomplete or simply misleading (I can't tell which).

In any case, the help system doesn't really explain what User1 ... User9 do or what benefit they add beyond just defining your own highlight groups. No examples are even provided.

Someone has to know why these special highlight groups where defined.

Thanks,
Jason

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