I am using Vim 8.2. I would like to change the color of the StatusLine
when I enter Command Line mode with /
and :
.
I have the following in my .vimrc
. It is supposed to change the background and foreground colors of the StatusLine
of the current window and the not-current windows
augroup InsertHook
autocmd!
" enter command line mode
autocmd CmdlineEnter * hi StatusLine gui=bold guifg=#7386A7 guibg=#FFE847
autocmd CmdlineEnter * hi StatusLineNC gui=NONE guifg=#FFE847 guibg=#9EA8BA
" leave command line mode
autocmd CmdlineLeave * hi StatusLine gui=bold guifg=#EFEEC9 guibg=#7386A7
autocmd CmdlineLeave * hi StatusLineNC gui=NONE guifg=#DFDBC5 guibg=#9EA8BA
augroup END
This kinda works, but only when I enter Command Line mode with a /
and then type something. It does not work when I enter Command Line mode with a :
.
I have played around with the above snippet of code, substituting CmdwinEnter
and CmdwinLeave
for CmdlineEnter
and CmdlineLeave
, respectively; and I have also tried CmdlineChanged
, but I cannot get the color of the StatusLine
to change instantly when entering Command Line mode with both :
and /
.
Any ideas?
Controlling the highlighting of the status line is unfortunately not that straightforward.
Here is a hack that changes the status line highlight for every window when you enter/leave the command line:
hi CmdlineEnter ctermbg=green ctermfg=white
hi CmdlineLeave ctermbg=blue ctermfg=white
augroup cmd
autocmd!
autocmd CmdlineEnter * let &statusline = '%#CmdlineEnter#%f'
autocmd CmdlineLeave * let &statusline = '%#CmdlineLeave#%f'
augroup END
I am not sure how it could be changed so that it only highlights the status line of the current window, though.