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

4

1

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"
endif

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

EDIT: 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?

still_dreaming_1

Posted 2011-06-30T05:37:39.423

Reputation: 239

Answers

4

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.

davidg

Posted 2011-06-30T05:37:39.423

Reputation: 389

Is there a different terminal that will let you change the cursor width or color? – still_dreaming_1 – 2011-06-30T16:16:55.673

1

@INTPnerd Mintty. It's derived from PuTTY, but it's generally more compatible with xterm and does support the xterm colour sequences (except that it only supports colour values, not names). It also implements a control sequence for changing cursor style. See this tip on how to put that to use in vim. Mintty requires Cygwin or MSYS though.

– ak2 – 2011-06-30T19:26:00.480

@ak2 Thanks! Mintty works for this, but there is an annoying delay before the cursor changes when changing modes. IDK if that's Mintty's fault or not... – still_dreaming_1 – 2011-06-30T21:13:54.207

1

@INTPnerd That's vim's escape timeout. See the next tip on how to avoid it.

– ak2 – 2011-07-01T03:04:55.033

I don't think that's it. I tried that tip and it did not help. The delay is not only when I press escape to leave insert mode but also when I enter insert mode. – still_dreaming_1 – 2011-07-01T16:17:38.583

1@INTPnerd Ah, that's a bug then, introduced in version 0.9. The cursor shape is only updated when the cursor blinks or moves, whereas of course it should be updated right away. – ak2 – 2011-07-02T11:00:05.673