Macos – “^[[O” and “^[[I” appearing on iTerm2 when focus lost


I’m using iTerm2 2.1.1 on Yosemite. No tmux.

When iTerm loses focus (when switched to another application by Cmd-Tab or clicking another window), a ^[[I and ^[[O seems to be sent to the terminal. This causes a ^[[I^[[O to appear, or more frustrating, in Vim, this combination opens another small buffer.

Sample: Pressing Cmd-Tab several times after starting cat

% cat

This only happens on iTerm and not on Also, it reproduces on bash or sh, so it doesn't seem to be a zsh issue. Some Googling suggested that this is a “focus” issue, but what is “focus” in the meanings of a terminal, and is there any way to disable or avoid this?

Best Answer

According to this:

Add support for reporting focus lost/gained. esc[?1004h turns it on; then the terminal sends esc[I when focusing, esc[O when de-focusing. Send esc[?1004l to disable.

Cmd-R to reset will turn off focus reporting (Thanks to this)