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