In my .vimrc
I have the following (based upon a tip on the vim Wikia):
if &term =~ "xterm\\|rxvt"
" use an red cursor in insert mode
let &t_SI = "\<Esc>]12;red\x7"
" use an orange-ish cursor otherwise
let &t_EI = "\<Esc>]12;\#FFA560\x7"
silent !echo -ne "\033]12;\#FFA560\007"
" reset cursor when vim exits
autocmd VimLeave * silent !echo -ne "\033]112\007"
endif
It is supposed to change the cursor from orange to red when I enter insert mode and change it back when I leave. However this only works if the way I enter insert mode moves the cursor, e.g. 'I' or 'a' but not 'i'. Additionally, if I enter and leave insert mode without having done anything (or moved the cursor), hitting 'escape' will move the cursor back one space, which turns the cursor red, instead of keeping it as orange.
Is there a way to fix this? I'm using xfce4-terminal
.
It works the same in gnome-terminal. If you wait a second it does change to the correct color, but I think that second or two are not controllable because the codes are inserted by vim based on events internally. I don't think that precise second can be fixed.