commit 72c7428b80d5ace26c027037af8c74ddd61d9d05
Author: Sean <seanlkml@sympatico.ca>
Date:   Fri Mar 11 00:12:22 2011 -0800

    Recognize private escape sequence to change cursor colour
    
    ESC[?2011h -> Enable Vim insert mode cursor
    		- write tmuxSI terminfo entry to terminal
    ESC[?2011l -> Disable Vim insert mode cursor
    		- write tmuxEI terminfo entry to terminal

diff --git a/input.c b/input.c
index d0a37b7..731cbd4 100644
--- a/input.c
+++ b/input.c
@@ -1170,6 +1170,9 @@ input_csi_dispatch(struct input_ctx *ictx)
 		case 1049:
 			window_pane_alternate_off(wp, &ictx->cell);
 			break;
+		case 2011:	/* disable vi cursor mode */
+			screen_write_vicursormode(&ictx->ctx, 0);
+			break;
 		default:
 			log_debug("%s: unknown '%c'", __func__, ictx->ch);
 			break;
@@ -1217,6 +1220,9 @@ input_csi_dispatch(struct input_ctx *ictx)
 		case 1049:
 			window_pane_alternate_on(wp, &ictx->cell);
 			break;
+		case 2011:	/* enable vi cursor mode */
+			screen_write_vicursormode(&ictx->ctx, 1);
+			break;
 		default:
 			log_debug("%s: unknown '%c'", __func__, ictx->ch);
 			break;
diff --git a/screen-write.c b/screen-write.c
index 4187cf6..d7e7fda 100644
--- a/screen-write.c
+++ b/screen-write.c
@@ -778,6 +778,18 @@ screen_write_cursormode(struct screen_write_ctx *ctx, int state)
 		s->mode &= ~MODE_CURSOR;
 }
 
+/* Set vi cursor mode. */
+void
+screen_write_vicursormode(struct screen_write_ctx *ctx, int state)
+{
+	struct screen	*s = ctx->s;
+
+	if (state)
+		s->mode |= MODE_VI_CURSOR;
+	else
+		s->mode &= ~MODE_VI_CURSOR;
+}
+
 /* Reverse index (up with scroll).  */
 void
 screen_write_reverseindex(struct screen_write_ctx *ctx)
diff --git a/tmux.h b/tmux.h
index 9753bd9..b442a85 100644
--- a/tmux.h
+++ b/tmux.h
@@ -321,8 +321,10 @@ enum tty_code_code {
 	TTYC_SMUL,	/* enter_underline_mode, us */
 	TTYC_VPA,	/* row_address, cv */
 	TTYC_XENL,	/* eat_newline_glitch, xn */
+	TTYC_TMUXSI,	/* enter vi insert cursor mode, SI */
+	TTYC_TMUXEI,	/* exit vi insert cursor mode, EI */
 };
-#define NTTYCODE (TTYC_XENL + 1)
+#define NTTYCODE (TTYC_TMUXEI + 1)
 
 /* Termcap types. */
 enum tty_code_type {
@@ -546,6 +548,7 @@ struct mode_key_table {
 #define MODE_MOUSE_BUTTON 0x40
 #define MODE_MOUSE_ANY 0x80
 #define MODE_MOUSE_UTF8 0x100
+#define MODE_VI_CURSOR 0x200
 
 #define ALL_MOUSE_MODES (MODE_MOUSE_STANDARD|MODE_MOUSE_BUTTON|MODE_MOUSE_ANY)
 
diff --git a/tty-term.c b/tty-term.c
index 473a434..138f621 100644
--- a/tty-term.c
+++ b/tty-term.c
@@ -183,6 +183,8 @@ const struct tty_term_code_entry tty_term_codes[NTTYCODE] = {
 	{ TTYC_SMUL, TTYCODE_STRING, "smul" },
 	{ TTYC_VPA, TTYCODE_STRING, "vpa" },
 	{ TTYC_XENL, TTYCODE_FLAG, "xenl" },
+	{ TTYC_TMUXSI, TTYCODE_STRING, "tmuxSI" },
+	{ TTYC_TMUXEI, TTYCODE_STRING, "tmuxEI" },
 };
 
 char *
diff --git a/tty.c b/tty.c
index d0b97a4..ee25b32 100644
--- a/tty.c
+++ b/tty.c
@@ -394,6 +394,12 @@ tty_update_mode(struct tty *tty, int mode)
 		else
 			tty_putcode(tty, TTYC_CIVIS);
 	}
+	if (changed & MODE_VI_CURSOR) {
+		if (mode & MODE_VI_CURSOR)
+			tty_putcode(tty, TTYC_TMUXSI);
+		else
+			tty_putcode(tty, TTYC_TMUXEI);
+	}
 	if (changed & ALL_MOUSE_MODES) {
 		if (mode & ALL_MOUSE_MODES) {
 			if (mode & MODE_MOUSE_UTF8)
