Numeric keypad keys in vi insert letters instead of numbers

I'm new to vi. Actually I'm using it just to modify small text files. I've a serious and unusual, I think, problem with the numeric keypad, as follow: I write vi IN and press enter. This make me access to the file named IN. Then I use arrow keys (or hjkl) to move the cursor through the file. Then I press i to activate the insert mode and write. Here comes the problem: numeric keypad doesn't work properly, since I get pqrstuvwxyl when I press 0123456789+ (,.-*/= still work).


Solution 1:

As far as I understand, there are two possible modes for number keypads of VT100 terminals: the normal Numeric keypad mode and the Application keypad mode. The latter has the keypad keys send not numbers, but escape sequences. E.g., the '1' key sends <ESC>[Oq, the '2' key sends <ESC>[Or, of which only the letters q and r are visible on the screen. These are control sequences that the program (host) may interpret as commands for some features. So, in this mode, the keypad keys are practically used as additional function keys.

In accordance with the VT100 terminal standard, a program (host) may 'ask' the terminal to switch the keypad to application mode. (It can do this by sending a specific control sequence to the terminal.) Vi and Vim are known to do this. The mode switch is not universal, but on a program to program base: it's only active in the program that requested it. In other programs, including the shell, the keypad remains in Number mode. The default setting in OS X's Terminal.app is to allow programs to switch to Application mode, which is what you now disabled by un-checking the option "Allow VT100 application keypad mode". (BTW: In OS X 10.7 this option is labelled "Strict VT100 keypad behaviour".)

See also:

http://www.vt100.net/docs/vt100-ug/chapter3.html https://ttssh2.osdn.jp/manual/en/usage/tips/appkeypad.html

Solution 2:

I solved the problem on my own, but I'd like to know WHY my solution works. I deselected the option the red arrow indicates in the following picture enter This is italian, but the english version of the same window is here

But I don't recall enabling this but there it is.