To set custom statusline text based on whether the window is active/inactive I followed the method here, which works by wrapping and expanding a function in the statusline format string that checks if a window ID matches the window ID that called the wrapper function.
Now I'm trying to set a custom highlight group for certain text that should only show up in the active window.
What I've tried:
hi StatusLineActiveHighlight ctermfg=white ctermbg=028 cterm=bold
hi StatusLineInactiveHighlight ctermfg=white ctermbg=130 cterm=bold
set laststatus=2 " always show statusline
set statusline= " clear
function ShowIfActive(wid)
if a:wid == win_getid()
return "%#StatusLineActiveHighlight#Active"
else
return "%#StatusLineInactiveHighlight#Inactive"
endif
endfun
function ShowIfActiveWrapper() abort
let l:wid = win_getid()
return "%{ShowIfActive(".l:wid.")}"
endfun
set statusline+=%!ShowIfActiveWrapper().'\ %f\ Line\ %l/%L'
The issue is that %#StatusLine[Active/Inactive]Highlight#
isn't being expanded - it's showing as the literal string. I tried following :h statusline
and tested with {%
instead of %{
to no avail.
I know that vim-airline
can do what I want, but I'm looking to make my statusline as DIY as I can and learn some more Vimscript in the process.