59

I just upgraded to zsh/oh-my-zsh. Almost immediately I notice on my machine that the 10-digit numpad is not working. It was working in bash and fish shell.

Oddly, if I hold down the fn/function key it acts like numlock and works, but it doesn't "lock" and I would have to keep holding down fn to type out the numbers.

Any ideas out there?

0

6 Answers 6

110

The numpad key do not send the same key symbols as the 'normal' number key in the top row. For example: The numpad-1-key sends KP_1 while the 1-key just sends 1.

Some terminals automatically remap the numpad key to send the same codes to the shell. Also, some shells (for example bash) just interprete the numpad keys like their equivalents in the main block.

zsh does not do the mapping automatically, but you can use bindkey to do the mapping on your own. I have the following in my ~/.zshrc to get the keypad working:

# Keypad
# 0 . Enter
bindkey -s "^[Op" "0"
bindkey -s "^[Ol" "."
bindkey -s "^[OM" "^M"
# 1 2 3
bindkey -s "^[Oq" "1"
bindkey -s "^[Or" "2"
bindkey -s "^[Os" "3"
# 4 5 6
bindkey -s "^[Ot" "4"
bindkey -s "^[Ou" "5"
bindkey -s "^[Ov" "6"
# 7 8 9
bindkey -s "^[Ow" "7"
bindkey -s "^[Ox" "8"
bindkey -s "^[Oy" "9"
# + -  * /
bindkey -s "^[Ok" "+"
bindkey -s "^[Om" "-"
bindkey -s "^[Oj" "*"
bindkey -s "^[Oo" "/"

bindkey -s in-string out-string binds in-string to out-string. If in-string is typed out-string is pushed back and treated as input.

The actual codes (for example ^[Oq) may be different on your system. You can press Ctrl+v followed by the key in question to get the code for your terminal.

6
  • 3
    Thank you sir, this worked perfectly for me and the Ctrl + v tip is great!
    – BradGreens
    Apr 16, 2014 at 14:12
  • 2
    Thanks, this was really useful but some keys were missing for the Apple USB keyboard. This is the key binding for Apple Keyboard: # Keypad # 0 . Enter bindkey -s "^[Op" "0" bindkey -s "^[On" "." bindkey -s "^[OM" "^M" # 1 2 3 bindkey -s "^[Oq" "1" bindkey -s "^[Or" "2" bindkey -s "^[Os" "3" # 4 5 6 bindkey -s "^[Ot" "4" bindkey -s "^[Ou" "5" bindkey -s "^[Ov" "6" # 7 8 9 bindkey -s "^[Ow" "7" bindkey -s "^[Ox" "8" bindkey -s "^[Oy" "9" # + - * / bindkey -s "^[Ok" "+" bindkey -s "^[Om" "-" bindkey -s "^[Oj" "*" bindkey -s "^[Oo" "/" bindkey -s "^[OX" "=" May 8, 2014 at 16:20
  • The manual for this: gnu.org/software/screen/manual/html_node/…
    – krowe
    Aug 22, 2014 at 0:53
  • and this is good too: stackoverflow.com/questions/18042685/…
    – krowe
    Aug 22, 2014 at 0:56
  • github.com/krowe/kshrc-k800-keybindings Made this based off this answer.
    – krowe
    Aug 22, 2014 at 12:27
22

To complete the answer that @adaephon gave, the following are the correct bindings for the Apple USB keyboard (A1243). These need to be added to ~/.zshrc.

# Fix numeric keypad
# 0 . Enter
bindkey -s "^[Op" "0"
bindkey -s "^[On" "."
bindkey -s "^[OM" "^M"
# 1 2 3
bindkey -s "^[Oq" "1"
bindkey -s "^[Or" "2"
bindkey -s "^[Os" "3"
# 4 5 6
bindkey -s "^[Ot" "4"
bindkey -s "^[Ou" "5"
bindkey -s "^[Ov" "6"
# 7 8 9
bindkey -s "^[Ow" "7"
bindkey -s "^[Ox" "8"
bindkey -s "^[Oy" "9"
# + -  * / =
bindkey -s "^[Ol" "+"
bindkey -s "^[Om" "-"
bindkey -s "^[Oj" "*"
bindkey -s "^[Oo" "/"
bindkey -s "^[OX" "="
2
  • 1
    Robin, could you expand your answer to include where OP should input this information to correct their problem? Oct 23, 2014 at 22:25
  • 2
    This worked for me except + (had to use bindkey -s "^[Ok" "+") and = (missing bindkey -s "^[OX" "=")
    – dain
    Jan 30, 2015 at 10:36
6

On MacOS Catalina with A1843 Apple Keyboard:

I set the Terminal configuration to ansi. It works with all the keys.

No keybindings needed.

Terminal.app Screenshot

iTerm Screenshot

2
  • 1
    This worked great! I added an iTerm screenshot.
    – Charlie
    Jul 13, 2021 at 23:36
  • Good that you have added iTerm too, worked for me as well, no binding was needed. Sep 28, 2021 at 18:41
4

Also complementing answer from @adaephon. Here is what I had to use for my Dell Desktop, might be of help. Just add it in your .zshrc file.

(BTW dont add bindings from all answers, you should just have one binding per key)

# Keypad
# 0 . Enter
bindkey -s "^[Op" "0"
bindkey -s "^[On" "."
bindkey -s "^[OM" "^M"
# 1 2 3
bindkey -s "^[Oq" "1"
bindkey -s "^[Or" "2"
bindkey -s "^[Os" "3"
# 4 5 6
bindkey -s "^[Ot" "4"
bindkey -s "^[Ou" "5"
bindkey -s "^[Ov" "6"
# 7 8 9
bindkey -s "^[Ow" "7"
bindkey -s "^[Ox" "8"
bindkey -s "^[Oy" "9"
# + -  * /
bindkey -s "^[OQ" "/"
bindkey -s "^[OR" "*"
bindkey -s "^[OS" "-"
bindkey -s "^[Ol" "+"
#END Keypad
2
  • Welcome to Super User! Could you please edit your answer to include a little guidance about what this is and how/where to use it?
    – Excellll
    Apr 29, 2015 at 18:28
  • This solution worked for me for zsh with windows keypad (PUTTY, with Terminal > Keyboard > Initial state of numeric pad > Normal) Apr 4, 2017 at 23:46
4

On my Mac OSX El Capitan, the period key is ^[0n instead of ^[01. Also I have a Logitech wireless keyboard for the Mac and it has an = sign on the numpad too. My final mapping looks like below:

# Keypad
# 0 . Enter
bindkey -s "^[Op" "0"
bindkey -s "^[On" "."
bindkey -s "^[OM" "^M"
# 1 2 3
bindkey -s "^[Oq" "1"
bindkey -s "^[Or" "2"
bindkey -s "^[Os" "3"
# 4 5 6
bindkey -s "^[Ot" "4"
bindkey -s "^[Ou" "5"
bindkey -s "^[Ov" "6"
# 7 8 9
bindkey -s "^[Ow" "7"
bindkey -s "^[Ox" "8"
bindkey -s "^[Oy" "9"
# + -  * / =
bindkey -s "^[Ok" "+"
bindkey -s "^[Om" "-"
bindkey -s "^[Oj" "*"
bindkey -s "^[Oo" "/"
bindkey -s "^[OX" "="

The solution others proposed works correctly however.

1

If you use Kitty to access a linux server on SSH and that the keypad is working fine with Bash but not with ZSH, you may try adding the following in your ~/.zshrc config file:

# Keypad
# 0 . Enter
bindkey -s "^[Op" "0"
bindkey -s "^[On" "."
bindkey -s "^[OM" "^M"
# 1 2 3
bindkey -s "^[Oq" "1"
bindkey -s "^[Or" "2"
bindkey -s "^[Os" "3"
# 4 5 6
bindkey -s "^[Ot" "4"
bindkey -s "^[Ou" "5"
bindkey -s "^[Ov" "6"
# 7 8 9
bindkey -s "^[Ow" "7"
bindkey -s "^[Ox" "8"
bindkey -s "^[Oy" "9"
# + -  * /
bindkey -s "^[Ol" "+"
bindkey -s "^[OS" "-"
bindkey -s "^[OR" "*"
bindkey -s "^[OQ" "/"

Save. Logout and login again to reload the ZSH config, or alternatively you can type the following in your terminal:

. ~/.zshrc

The keypad should now work as expected!

2
  • This duplicates another answer and adds no new content. Please don't post an answer unless you actually have something new to contribute.
    – DavidPostill
    Dec 21, 2016 at 15:03
  • Let me disagree. Only this answer has similar codes : superuser.com/a/907695/351420 And I explain the context and how to use those codes, imho better than this answer. Jan 4, 2017 at 9:53

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.