Answers:
小键盘键发送的密钥符号与第一行中的“普通”数字键不同。例如:numpad-1-key发送,KP_1
而1-key只是发送1
。
某些终端会自动重新映射小键盘键,以将相同的代码发送到外壳。另外,某些外壳程序(例如bash
)仅将小键盘上的键解释为与主程序段中的键等效。
zsh
不会自动进行映射,但是您可以使用bindkey
它自己进行映射。~/.zshrc
为了使键盘正常工作,我准备了以下设备:
# 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
绑定in-string
到out-string
。如果in-string
键入,则将其out-string
推回并视为输入。
^[Oq
您的系统上的实际代码(例如)可能有所不同。您可以按Ctrl+,v然后按相应的键以获取终端的代码。
要完成@adaephon给出的答案,以下是Apple USB键盘(A1243)的正确绑定。这些需要添加到中~/.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" "="
+
有用,除了(必须使用bindkey -s "^[Ok" "+"
)和=
(缺少bindkey -s "^[OX" "="
)
还补充了@adaephon的答案。这是我在Dell台式机上必须使用的功能,可能会有所帮助。只需将其添加到您的.zshrc文件中即可。
(顺便说一句,不要从所有答案中添加绑定,每个键只能有一个绑定)
# 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
Terminal > Keyboard > Initial state of numeric pad > Normal
)
在我的Mac OSX El Capitan上,句号是^[0n
而不是^[01
。我也有一个Mac专用的Logitech无线键盘,并且=
在小键盘上也有一个标志。我的最终映射如下所示:
# 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" "="
但是其他人提出的解决方案可以正常工作。
如果您使用Kitty在SSH上访问Linux服务器,并且键盘可以在Bash上正常工作,但不能在ZSH上正常工作,则可以尝试在~/.zshrc
配置文件中添加以下内容:
# 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" "/"
保存。注销并再次登录以重新加载ZSH配置,或者您也可以在终端中键入以下内容:
. ~/.zshrc
键盘现在应该可以正常工作了!
Ctrl
+v
提示很棒!