Different vim colorscheme depending on mode

vim

I'm often doing the same mistake in vim:

  • I forget whether I'm in insert or command mode, then I type in, I get random commands or I modify/delete code, and I have to undo. I do this mistake really too often.

I was thinking of using the :colorscheme my_color_file to switch between two color schemes depending if I'm in insert mode or not.

Basically, the command_color_file.vim has a red signature(keywords, tabs) for command mode, while the insert_color_file.vim has a green signature.

However I don't find how to perform the :colorscheme call any time I enter one mode or another.

Any idea if it is possible to do that?

Best Answer

I haven't tested, but try something like this:

:autocmd InsertEnter * :colorscheme my_color_file_insert
:autocmd InsertLeave * :colorscheme my_color_file_command

This page, about Event-driven scripting in Vim seems to have a good description of how to do it

Related Question