How do I get the numpad to work in vim using iterm2 on osx with term=xterm?

50

4

My numpad works in iterm2 (bash), but it inserts characters instead of numbers in insert mode for vim.

How can I get vim to recognise the correct escape codes.

I have tried editing the escape codes as suggested here without any luck: http://code.google.com/p/iterm2/issues/detail?id=702

J0hnG4lt

Posted 2013-03-13T10:23:10.217

Reputation: 1 561

Answers

85

Looks like the answer is to go into Preferences->Profiles->Keys and load preset of: "xterm with Numeric Keypad".

J0hnG4lt

Posted 2013-03-13T10:23:10.217

Reputation: 1 561

1

I didn't have this preset, so in my answer I explained how you can add these shortcuts yourself.

– gitaarik – 2015-07-13T09:05:55.927

It appears that the preset no longer exists in iTerm 2.1.1 – scarver2 – 2015-08-14T17:28:34.720

1Recently did a new OS install. The preset is still there in iTerm 2.1.1. – J0hnG4lt – 2015-10-02T16:10:09.080

3Works in iTerm 2.1.4 too, though I also had to add a new shortcut to insert hex key code 0xd for NumPad's Enter key to work. (Weirdly not detected as the Num-⏎ key already registered, but as ⏎ on its own, when set up.) – ecmanaut – 2016-02-23T19:34:53.373

1Works for me. I'm using iTerm2 Build 2.1.4. – KLaw – 2016-04-20T15:48:20.123

Latest beta, preset's gone (again?). – J0hnG4lt – 2019-03-29T10:19:03.350

20

For me the solution was disabling VT100 Application Keypad-Mode in Preferences > Profiles > Advanced.

mansur

Posted 2013-03-13T10:23:10.217

Reputation: 319

3This solution works only on the native terminal, but not with iTerm – crazyGuy – 2015-12-16T09:36:03.027

13

You can add global keyboard shortcuts in Preferences -> Keys and map the numpad characters to "Send Text" actions to send the text they are supposed to send.

iTerm2 keys preferences

gitaarik

Posted 2013-03-13T10:23:10.217

Reputation: 490

7For the Enter key, choose the Send Hex Codes action and enter 0x0D. – scarver2 – 2015-08-14T17:34:00.547

8

but it removes some colors in my vim.

if you just need it some times, just type:

:set term=ansi

in VIM

Best regards

OskarStark

Posted 2013-03-13T10:23:10.217

Reputation: 191