124

The numberpad does not work properly when using Vim through PuTTY. Instead of numbers I get

y
x
w
v
u
t
s
r
q
Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
Pykler
  • 13,495
  • 9
  • 39
  • 47

5 Answers5

198

The answer is in Numpad in PuTTY while using vi [Cialug]:

In the configuration, go to Terminal->Features and check "Disable application keypad mode". Save the settings and enjoy a numeric pad that works!

Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
Pykler
  • 13,495
  • 9
  • 39
  • 47
  • 24
    After 5 years this was the only thing about Putty which used to annoy the hell out of me – John Magnolia Dec 27 '12 at 22:17
  • 5
    I'd also love to know why it's not enabled by default. Does it break numpad usage in any other application? http://the.earth.li/~sgtatham/putty/0.60/htmldoc/Chapter4.html#config-appkeypad BTW disabling app keypad mode also fixes that "," is being entered in bash when you press numpad "+". – user323094 Sep 08 '13 at 19:51
  • 2
    Thought I'd add this simple key-mapping solution (http://twitpic.com/97qyww) for iTerm users. – Andy Barbour May 02 '14 at 04:20
  • 2
    @Pykler This disables an important feature of the emulated terminal, so it’s not a great idea to have it disabled by default. What’s difficult to understand is why Vim enables Application Keypad Mode by default but doesn’t provide any default mappings for the keys. – Chris Page May 22 '14 at 04:31
  • 11
    On the Mac Terminal app, try Preferences --> Profiles --> Advanced --> deselect "Allow VT100 application keypad mode" – HaPsantran Nov 12 '14 at 15:36
  • 7
    Does anyone know why this feature/bug is there? Is there a link to some historical reference about this? Thanks :) – Atcold Dec 30 '14 at 18:22
  • 2
    NOTE: The bug is that Vim enables Application Keypad Mode without defining any mappings for it. I haven't found an explanation for this behavior. Putty, Terminal and XTerm—and others like them—are behaving correctly: they emulate a terminal with AKM and Vim asks for it to be enabled, so it is. – Chris Page Dec 10 '15 at 11:46
  • This was annoying me for a long time - thanks for the help @Pykler. – William Orazi Aug 22 '16 at 18:03
  • Thanks for the answer! Interesting result -- disabling all of the other features seems to have absolutely no negative effect, so, I'll just keep them all permanently disabled. – HoldOffHunger Jun 14 '20 at 19:29
16

I have always used this set of mappings to interpret the escape sequences as numbers when $TERM=xterm

imap <Esc>Oq 1
imap <Esc>Or 2
imap <Esc>Os 3
imap <Esc>Ot 4
imap <Esc>Ou 5
imap <Esc>Ov 6
imap <Esc>Ow 7
imap <Esc>Ox 8
imap <Esc>Oy 9
imap <Esc>Op 0
imap <Esc>On .
imap <Esc>OR *
imap <Esc>OQ /
imap <Esc>Ol +
imap <Esc>OS -

I think this was my original source.

Michael Berkowski
  • 253,311
  • 39
  • 421
  • 371
  • 1
    Yeah, your link has the same solution as mine, which is to disable application keypad mode in putty, the vim remap works but according to your link is unnecessary – Pykler Sep 02 '11 at 14:15
  • @Pykler I'm often forced to use PuTTY from machines that aren't my own, and have a dozen saved sessions on my regular machine. The vimrc mapping removes the need for me to always be changing settings when creating a new session or working from an unfamiliar machine. – Michael Berkowski Sep 02 '11 at 14:19
  • How do you solve setting up vim on all the machines you ssh to? Maybe thats a question on its own, but I find that my vimrc's and zshrc's get out of sync quickly. Also I don't really use windows / putty often, for now it is a single machine at work :) – Pykler Sep 02 '11 at 14:21
  • @Pykler I rsync my vim configs usually only once. I don't care if they get out of sync, except on one or two important development machines, but I do care about having a baseline config including this and a handful of other settings. – Michael Berkowski Sep 02 '11 at 14:25
  • I use Vim with Putty with more than 30 students every year, so it seems to me easier to change the vimrc file instead of tell the students to change their settings. So for me it is a useful solution. – Arpad Horvath Mar 28 '14 at 09:13
15

And for Mac, the answer is in a comment by HaPsantran on this same page and there is a similar answer by nfechner with German screenshots in this answer.

For Mac, go to your Terminal application. Select Preferences, Profiles, Advanced and deselect Allow VT100 application keypad mode.

enter image description here

Community
  • 1
  • 1
Kirby
  • 13,024
  • 6
  • 79
  • 95
5

If using SSH through a terminal you can just go to

Edit -> Num Lock (third from bottom)

It needs to have a checkmark to the left of it.

Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
kavakava
  • 61
  • 1
  • 1
  • 2
    What context? Has this anything to do with PuTTY (which the question is about)? What application are you talking about? PuTTY does not have an "Edit" menu. Where is "Edit"? What application? On what platform? For instance, the Ubuntu application "Terminal" does not have a menu item named "Edit". – Peter Mortensen Apr 15 '19 at 14:11
2

The previous answers by kirby, michael-berkowski, and pykler are great.

I had this issue in Vim on macOS's terminal. Checking TerminalPreferencesProfilesKeyboard showed that "Clear (Keypad)" was mapped to "Num Lock". Pressing clear fixed the issue for me.

Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
Dave
  • 2,008
  • 1
  • 19
  • 24