Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change color of cursor in gvim

Tags:

vim

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.

like image 949
Linus Oleander Avatar asked May 28 '11 00:05

Linus Oleander


People also ask

How do I highlight a cursor in Vim?

Simply putting :set cursorline in your vimrc will highlight the current line in every window and update the highlight as the cursor moves. With the default backslash leader key, typing \c will toggle highlighting on and off. That makes it easy to locate the cursor after scrolling in a large file.

What is cursor in Vim?

Vim allows the cursor shape, blink rate, and color to be customized, if supported by the underlying system. Depending upon your system, you can make the cursor more prominent using blinking and a distinctive color, or you can make the cursor less distracting by disabling blinking and using a bland color.


2 Answers

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
like image 144
Linus Oleander Avatar answered Sep 19 '22 13:09

Linus Oleander


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.

like image 28
Random832 Avatar answered Sep 19 '22 13:09

Random832