(cleaning up random imported tip) |
|||
Line 58: | Line 58: | ||
==Comments== |
==Comments== |
||
+ | This works when I enter insert mode for the first time and changes the colours properly when i leave insert mode, however after that the colour of the status line stays the same regardless of what mode I am currently in. |
||
+ | Could it be something to do with other Vim settings? |
Revision as of 13:11, 28 January 2010
created July 18, 2006 · complexity basic · author Yakov Lerner · version n/a
The following small piece changes the color of the statusline when you enter insert mode, and when you leave insert mode. There are no mapping keys or new commands to remember, it works totally automatically.
The color codes below are Green in normal mode, and Magenta in insert mode. If you like other colors, just change them.
" first, enable status line always set laststatus=2 " now set it up to change the status line based on mode if version >= 700 au InsertEnter * hi StatusLine term=reverse ctermbg=5 gui=undercurl guisp=Magenta au InsertLeave * hi StatusLine term=reverse ctermfg=0 ctermbg=2 gui=bold,reverse endif
If you want a different color based on the kind of insert mode you are in (i.e. insert, replace, or virtual insert), then you can use the v:insertmode variable during the InsertEnter event execution to do something different in each mode. For example:
function! InsertStatuslineColor(mode) if a:mode == 'i' hi statusline guibg=magenta elseif a:mode == 'r' hi statusline guibg=blue else hi statusline guibg=red endif endfunction au InsertEnter * call InsertStatuslineColor(v:insertmode) au InsertLeave * hi statusline guibg=green " default the statusline to green when entering Vim hi statusline guibg=green
References
See also
- :help 'showmode' for another way to indicate mode
- :help hl-ModeMsg if you want to change the color of the above
Comments
This works when I enter insert mode for the first time and changes the colours properly when i leave insert mode, however after that the colour of the status line stays the same regardless of what mode I am currently in. Could it be something to do with other Vim settings?