Windows – over Windows terminal change cursor width or color in Vim depending on mode

puttyterminalvimwindows 7

I am using PuTTY to connect over SSH to an Ubuntu server from my Windows 7 workstation. Once connected I am using the Vim installation from the Ubuntu server to edit files. I want the cursor to change when I go into and out of insert mode. Part of my .vimrc file is like this but it is not changing the cursor:

if &term =~ "xterm"
    echo "xTerm!!inate!"
    let &t_SI = "\<Esc>]12;purple\x7"
    let &t_EI = "\<Esc>]12;blue\x7"

I know that the if statement is executing because of the echo.

Actually I would prefer to change the cursor to be a vertical line like you can in the PuTTY settings rather than change the color, or maybe even do both. But just changing the color would be a lot better than nothing. Also I am willing to change terminals if there is another Windows 7 Professionsal 64 bit compatible terminal that can do this (preferably something free). Maybe Poderosa can do this?

Best Answer

Your example appears to work just fine using xterm, so I don't think it is your .vimrc that is the problem.

Digging a little deeper, it appears that PuTTY doesn't appear to implement the OSC escape code that you are using to change the colour of the cursor (see do_osc in terminal.c in the PuTTY sources). Browsing the sources, I couldn't find any other mechanism to do something similar, either. This means that there probably isn't going to be an easy way to get this working in PuTTY.

Your solutions are thus likely to be limited to:

  1. Trying to plead with the PuTTY authors to implement the relevant OSC escape code;
  2. Changing your terminal program; or
  3. Finding another way to let vim know what mode you are in.

I suspect the third is going to be the easiest, unfortunately.