vim is assuming that iTerm2 is xterm (not a good assumption), and attempting to determine the state of the cursorBlink
resource by sending an escape sequence containing $p
which iTerm2 does not handle properly (see source-code for vim for the escape sequence, and also where it uses the feature). While vim starts with the TERM
setting (i.e., "xterm"), it does make a few checks to exclude things like gnome-terminal as noted in the source code comment. But iTerm2 happens to fool vim in this case. So the result goes to the screen.
In XTerm Control Sequences that is documented like this:
CSI ? Ps$ p
Request DEC private mode (DECRQM). For VT300 and up, reply is
CSI ? Ps; Pm$ y
where Ps is the mode number as in DECSET/DECSET, Pm is the
mode value as in the ANSI DECRQM.
Two private modes are read-only (i.e., 1 3 and 1 4 ), pro-
vided only for reporting their values using this control
sequence. They correspond to the resources cursorBlink and
cursorBlinkXOR.
Although vim is fooled here, the problem is due to iTerm2, for which you've probably set the TERM
environment variable to xterm-256color
, or something like that. It doesn't match iTerm2's behavior very well (the function keys don't match up, etc). ncurses provides a better one. But out-of-the-box MacOS has a terminal database that's about ten years old, and lacks that entry. To get a good terminal database (i.e., one where you could set TERM
to iterm2
), you could do that with MacPorts or home-brew.
Running infocmp to get a measure of the differences between the (correct) iterm2
entry and linux
, xterm-256color
shows that
- it's actually closer to
nsterm-256color
(a correct entry for Terminal.app which Apple doesn't provide) with 38 lines of difference,
- next closest
linux
with 76 lines and
- still further away from
xterm-256color
with 94 lines.
The feature that's missing or mis-implemented in iTerm2 isn't in the terminal description: it's a special feature that vim has to guess about.