different background color for Insert/Normal mode

46 views
Skip to first unread message

bill lam

unread,
Apr 19, 2008, 10:23:53 AM4/19/08
to vim...@googlegroups.com
Hello,

I want to customize vimrc to change background color to yellow when switched to
"Insert mode". It should be easy but I can not find how to do it. Any help will
be appreciated.

regards,

Tony Mechelynck

unread,
Apr 19, 2008, 11:14:24 AM4/19/08
to vim...@googlegroups.com

:au InsertEnter * hi Normal term=reverse ctermbg=darkgrey guibg=yellow
:au InsertLeave * hi Normal term=NONE ctermbg=black guibg=white

Change to taste.

see
:help InsertEnter
:help InsertLeave
:help :autocmd
:help :highlight


Best regards,
Tony.
--
ARTHUR: Go on, Bors, chop its head off.
BORS: Right. Silly little bleeder. One rabbit stew coming up.
"Monty Python and the Holy Grail" PYTHON (MONTY)
PICTURES LTD

bill lam

unread,
Apr 19, 2008, 11:39:03 AM4/19/08
to vim...@googlegroups.com
Tony Mechelynck wrote:
> Change to taste.

Thanks, I settled for lightcyan.

regards,

John Little

unread,
Apr 20, 2008, 3:33:50 AM4/20/08
to vim_use


> I want to customize vimrc to change background color to yellow when switched to
> "Insert mode"...

A bit drastic, methinks (and sometimes ineffective if your syntax
highlighting sets the background colour, as I do for comments).
If you are using the gui, have you considered changing the shape and
colour of the cursor? See :h guicursor for the details.
Or, the colour of the statusline can be changed, even out of the gui,
using autocommands like Tony's altering "Normal" to "StatusLine", or
even part of it using the %1* construct and setting the User1
highlight group in the autocommands.

(BTW, vim has support for changing the cursor in insert mode in
terminals, but none of xterm, gnome-terminal or konsole seem to do it,
at least out of the box.)

HTH, John

Tony Mechelynck

unread,
Apr 20, 2008, 8:07:50 AM4/20/08
to vim...@googlegroups.com
On 20/04/08 09:33, John Little wrote:
[...]

> (BTW, vim has support for changing the cursor in insert mode in
> terminals, but none of xterm, gnome-terminal or konsole seem to do it,
> at least out of the box.)
>
> HTH, John

The Dos/Windows console Vim can use a limited set of 'guicursor'
settings (it can change the height, but not the width, of its cursor).
For other terminals, you have to find out which control codes (if any)
can be used to change the cursor shape and/or the cursor colour, and set
them as the values of 't_SI' (start insert) and 't_EI' (end insert).
These codes are not defined by the termcap/terminfo databases (their
default value is always the empty string), you have to set them
yourself. See ":help termcap-cursor-shape" for details.

Best regards,
Tony.
--
We ARE as gods and might as well get good at it.
-- Whole Earth Catalog

bill lam

unread,
Apr 20, 2008, 10:22:35 AM4/20/08
to vim...@googlegroups.com

I think that guicursor is available on my gvim. However I can not always notice
the big bold "INSERT" word in the status line, not to mention that small change
in cursor.

regards,

Tony Mechelynck

unread,
Apr 20, 2008, 10:58:50 AM4/20/08
to vim...@googlegroups.com

Yes, 'guicursor' is available in all versions of gvim when run in GUI
mode (the paragraph from John's post was about Console mode). I use a
big black block cursor in Normal mode, a vertical bar in Insert mode, a
horizontal underscore in Replace mode, and I make it blink at the rate
of .75 seconds on, .75 seconds off in all modes (i.e., at a frequency of
1.5 Hz). I don't have any problem noticing it. Here's my whole setting:

:set
gcr=n-v-c:block-Cursor/lCursor,ve:ver35-Cursor,o:hor50-Cursor,i-ci:ver25-Cursor/lCursor,r-cr:hor20-Cursor/lCursor,sm:block-Cursor,a:blinkwait750-blinkoff750-blinkon750

:hi Cursor gui=NONE,reverse


Best regards,
Tony.
--
Hail to the sun god
He sure is a fun god
Ra! Ra! Ra!

Benjamin Fritz

unread,
Apr 20, 2008, 1:06:02 PM4/20/08
to vim...@googlegroups.com

Just a thought (and I don't use this) but if you have been having
problems with forgetting that you are in insert mode, this tip might
be useful:


http://vim.wikia.com/wiki/To_switch_back_to_normal_mode_automatically_after_inaction

Reply all
Reply to author
Forward
0 new messages