Change color of cursor in vim

Tag: vim Author: makueiyuan Date: 2011-05-11

I want to change the color of the cursor pending on the current mode.

Here is my code so far (.gvimrc).

set gcr=n:blinkon0
set gcr=i:blinkon0
highlight Cursor guifg=white guibg=red
highlight iCursor guifg=white guibg=green

Right now the cursor is gray, nothing changes. Running highlight Cursor guifg=white guibg=red manually works, but not the line below.

I want the color green in insert mode and red in every other mode.

Best Answer

I got some help from the vim irc @ freenode.

Here is the solution.

au InsertLeave * hi Cursor guibg=red
au InsertEnter * hi Cursor guibg=green

Other Answer1

You have to actually specify the highlight group in the gcr setting. You also need to put them together, your second "i:" one overrides the first. It also overrides all your defaults, so even combining them doesn't cover the other modes, or the different shapes in modes like operator pending... check out the documentation. Try just altering the default to set your iCursor group on insert mode.

set gcr=n-v:block-Cursor/lCursor,c:block-iCursor/lCursor,ve:ver35-Cursor,o:hor50-Cursor,i-ci:ver25-iCursor/lCursor,r-cr:hor20-iCursor/lCursor,sm:block-Cursor-blinkwait175-blinkoff150-blinkon175

This is based on the defaults, except i, ci, r, cr, and c (insert, replace, and command line) all use your iCursor group.