My vimrc sets the buffer number in the statusline with a different color background based on if it's readonly or modified.
I'd also like to set a different color if the buffer is not in the active window (useful when in split window mode).
I am using &mod and &readonly to detect for modified or read-only. How can I check for whether the buffer is in the active window? (i.e. maybe change it to gray if the window is inactive).
Here's the code I'm using for read-only and modified:
function! StatusLineHeader()
return ' '.bufnr('%').' '
endfunction
set statusline=
set statusline+=%#UWhiteOnBlue#%{&mod?'':&readonly?'':StatusLineHeader()} "default header
set statusline+=%#UWhiteOnOrange#%{&mod?'':&readonly?StatusLineHeader():''} "readonly header
set statusline+=%#UWhiteOnGreen#%{&mod?StatusLineHeader():''} "modified header
First of all, generally it's a bad idea to use too many colors in the status line. You'd really better drop to predefined
StatusLine / StatusLineNC / %*which are set up automatically, i.e.But if you really want it, you need
:h g:actual_curwin. So it becomes:Note:
g:actual_curwinwas added in Vim 8.1.1372