Num layer switching issues with vim in terminal

When I am in insert mode in vim (iterm2) and I press the num key to switch to layers, it takes me out of insert mode as though escape had been pressed.

This does not affect GUI versions of vim such as VimR nor any terminal app other than vim. Behavior is the same if I start vim with -u NONE to disable my vimrc.

If I use Terminal (instead of iterm), after pressing the num key once the num layer is fine, on second press num layer is off and everything is fine. On the third press, num layer is on but no num keys generate any input. In other words, num layer works only every other time it is enabled.

I suspect that you’re using an old version of the firmware, which still sends NumLock when the num is pressed. Apple never used NumLock or separate keycodes for the numeric keypad, and this is most noticeable in terminal windows.