1

I use the following code to have different statusline colors for Normal and Insert modes:

                      highlight statusLine  ctermfg=black ctermbg=red    guifg=red   guibg=black
autocmd InsertLeave * highlight statusline  ctermfg=black ctermbg=red    guifg=red   guibg=black
autocmd InsertEnter * highlight statusline  ctermfg=black ctermbg=green  guifg=green guibg=black

It works fine for me except the color is not changed back to red when I exit from Insert mode by using <C-C>.

Some people suggest to use something like

inoremap <c-c> <c-o>:highlight statusline guifg=red guibg=black<cr><c-c>

for this, but it doesn't work for me. What's wrong with this line?

Also, why not use just inoremap <c-c> <Esc>? It looks much simpler and it works, but I suspect there are some hidden drawbacks.

1

It works fine for me except the color is not changed back to red when I exit from Insert mode by using .

If you do :h i_CTRL-C you'll get answer on why your statusline is not changed when you hit <C-c>:

                        *i_CTRL-C*
CTRL-C      Quit insert mode, go back to Normal mode.  Do not check for
        abbreviations.  Does not trigger the |InsertLeave| autocommand
        event.

Some people suggest to use something like inoremap <c-c> <c-o>:highlight statusline guifg=red guibg=black<cr><c-c>

If you use terminal without termguicolors on, then it wouldn't work for you, because you reset gui colors. Check your original autocommands where you set both term and gui colors. Try maybe

inoremap <c-c> <c-o>:highlight statusline ctermfg=black ctermbg=red guifg=red guibg=black<cr><c-c>

And it would probably not work because highlighting is applied to statusline in-between insertleave/insertenter (<C-o> switches to normal mode for a single command and then goes back to insert mode)

You can try this instead, where highlighting happens after original <C-c:

inoremap <c-c> <c-c>:highlight statusline guifg=red guibg=black<cr>

Also, why not use just inoremap <c-c> <Esc>? It looks much simpler and it works, but I suspect there are some hidden drawbacks.

You can use it if you don't mind loosing original <C-c> behavior described in the help above.

2
  • Sorry for not mentioning it, but I use gVim. The current solution doesn't seem to work for it. Even more, the cursor doesn't change from bar to block (weird!)
    – john c. j.
    Sep 18 at 20:19
  • @johnc.j. it doesn't work because your highlighting happens in-between 2 autocommands you have defined in the first place. Updated the answer.
    – Maxim Kim
    Sep 19 at 6:11

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.