Gibbserv.net

Icon

A slow updating blog I write for no particular reason.

^[[O and ^[[I Haunts me!!!

So I noticed today that if I detach a tmux session and then switch between my terminal (iTerm2) and other windows, ^[[O gets printed to the terminal when focus changes and ^[[I when focus returns to the terminal. This bugged the hell out of me. Particularly when jumping into another tmux session with vim running. Now if I enter Insert Mode and jump to Chrome to look at something, or in my case today jumping into an email with some code I wanted to copy, and I jump back to my terminal running tmux and vim I paste from my clipboard – everything gets crazy. Since ^[[O and ^[[I get sent to vim when leaving and returning, vim drops out of Insert Mode (and Visual Mode blah blah blah) and pasting is a shit show. I spent an hour just remembering to re-enter the mode I was in when I refocused to my terminal but it got old fast. Killing iTerm2 would return expected behavior until I detached a tmux session again. Hitting Ctrl+R in iTerm2 would resolve the issue until again, a tmux session was detached. Thanks to the following links below I was able to find that a ticket was recently opened with the tmux developer over at sourceforge and a fix was pushed up to master to correct an issue where tmux was keeping focus enabled after detaching a session.

https://github.com/sjl/vitality.vim/issues/2
http://sourceforge.net/p/tmux/tickets/176/

Here is the diff of what fixed it.

diff --git a/tty.c b/tty.c
index 9f57c36..534d239 100644
--- a/tty.c
+++ b/tty.c
@@ -290,7 +290,7 @@ tty_stop_tty(struct tty *tty)
if (tty_term_has(tty->term, TTYC_XT)) {
if (tty->flags & TTY_FOCUS) {
tty->flags &= ~TTY_FOCUS;
- tty_puts(tty, "\033[?1004l");
+ tty_raw(tty, "\033[?1004l");
}
}

If you installed tmux via Homebrew you can do what I did and remove tmux_1.9a and instead run brew install --HEAD tmux to build from master instead of using the tarball from 2014.