Search code examples
vimhighlightingmode

Vim: Different line-number color in the different modes


I've just started using Vim and I find myself being confused on which mode I'm currently in. I was wondering if it's possible to change the line number color (which I have displayed by default) in the different modes (command, visual, and insert) so that I can easily identify it.


Solution

  • Vim has an option called showmode that will put a message on the last line if you are not in normal mode. See :help 'showmode' for more info.

    If you really want to change the background of the number column while in insert mode, you could do something like the following:

    autocmd InsertEnter * highlight LineNr ctermbg=red   guibg=red
    autocmd InsertLeave * highlight LineNr ctermbg=black guibg=black
    

    Note that this method will break if you are bad and use C-c to exit insert mode instead of <Esc> or <C-[.

    Relevant :help tags: autocmd, autocmd-events, highlight, highlight-groups