2

I am experimenting with creating a statusline and have opted for coloring different parts of it.

The problem is that while the item's foreground color is changed, the background is black and doensn't match the statusline, e.g.:

set statusline+=%([%1*%t%*]%)

How can I set the item's background color to match the statusline (or turn it "transparent")?

set filetype=vim
set laststatus=2
set showcmd
set showmode
set termguicolors

" %-0{minwid}.{maxwid}{item}

" :help gui-colors
hi User1 guifg=Green guibg=fg
hi User2 guifg=Purple guibg=fg
hi User3 guifg=Cyan guibg=fg
hi User4 guifg=Red guibg=fg
hi User5 guifg=Orange guibg=fg

set statusline=%([%f]%)
set statusline+=%(%m%r%w%h%)
set statusline+=%(%y%)

set statusline=
set statusline+=%([%1*%t%*]%)
set statusline+=%5*%(%m%r%w%h%)%*
set statusline+=%(%y[%{&expandtab?'S':'T'}]%)
set statusline+=%=%<%([%3*%l,%c%V%*]%)
set statusline+=%([%3*%P%*]%)
"set statusline+=%([%3*%l,%c%*]%)
set statusline+=%(%a%)

enter image description here

0

This is answered directly under :h 'statusline'.

The syntax is simply %*. The actual highlight group will be one of StatusLine, StatusLineNC, StatusLineTerm, StatusLineTermNC just as expected.

UPD. Real highlight groups (not that "percent-star") are coloured globally by :highlight command. Even though User1 is primarily intended for status line(s), it doesn't make it anything special. So you can link it to StatusLine or StatusLineNC, but not both at the same time. It really has nothing to do with status lines, just usual combo of :execute, :highlight, synIDattr(), synIDtrans() and hlID() left as an excercise.

2
  • I think the idea was to make User1 the same background as whatever StatusLine* group is active (or at least one of them) – D. Ben Knoble Feb 8 at 21:45
  • @D.BenKnoble Updated. As it is, the question is not about status lines, but rather "how do I use :hi command?" – Matt Feb 9 at 7:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.