15

In several terminal programs, such as PuTTY, SecureCRT, iTerm, and Mac OS Terminal, if I have NumLock on and I press the number pad (numpad) keys 0123456789 in insert mode, my vim looks like this:

y                                                                                                          
x
w
v
u
t
s
r
q
p

~

If I use the numpad on the command line, it enters the numbers I expect.

How do I make vim type the right characters from the numpad?

2 Answers 2

28

Short answer

Turn off “application keypad mode switching.”

Terminal-specific instructions

  • PuTTY (also here): Terminal > Features > uncheck Disable application keypad mode
  • SecureCRT: Session Options > Terminal > Emulation > Modes > Mode switching > uncheck Enable keypad mode switching
  • iTerm: Switch to iTerm2 or see general instructions below.
  • iTerm2 (also here): Preferences > Profiles > Keys > Load Preset… > xterm with Numeric Keypad or add the settings manually as shown here.
  • Mac OS Terminal (also here): Preferences > Profiles > Advanced > uncheck Allow VT100 application keypad mode
  • Other: look for an option like application keypad mode or see below.

General instructions for .vimrc

If the terminal-specific instructions don't work for you, you can fix it in vim by adding the following mappings to your .vimrc:

:inoremap <Esc>Oq 1
:inoremap <Esc>Or 2
:inoremap <Esc>Os 3
:inoremap <Esc>Ot 4
:inoremap <Esc>Ou 5
:inoremap <Esc>Ov 6
:inoremap <Esc>Ow 7
:inoremap <Esc>Ox 8
:inoremap <Esc>Oy 9
:inoremap <Esc>Op 0
:inoremap <Esc>On .
:inoremap <Esc>OQ /
:inoremap <Esc>OR *
:inoremap <Esc>Ol +
:inoremap <Esc>OS -
:inoremap <Esc>OM <Enter>
1
  • 1
    The fundamental question is: why does Vim enable Keypad Application Mode without mapping the resulting function-key input to something? (Either digit input or the typical cursor movement and scrolling keys.) Why do all these terminal emulators have to have a way to ignore the enable-KAM command?
    – Chris Page
    Mar 18, 2021 at 0:07
0

SecureCRT, Options> Session Options> Terminal> Emulation>Modes>

Initial Modes and Current Modes sections, select Numeric keypad.

I found my Current modes was set to Application keypad when I wanted Numeric keypad to be default.

1
  • Welcome to Vi and Vim! It would improve this answer to edit and explain what terminal this concerns and what the difference between "Application keypad" and "Numeric keypad" is.
    – D. Ben Knoble
    Aug 9, 2022 at 18:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.