Tuesday, May 9, 2017

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

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.

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