我知道如何将 [AltGr] + [h|j|k|l] 键映射到箭头键,例如:
[AltGr]+[h] ... [Left]
[AltGr]+[j] ... [Down]
[AltGr]+[k] ... [Up]
[AltGr]+[l] ... [Right]
[AltGr]+[ö] ... [Home]
[AltGr]+[ä] ... [End]
这可以通过两个步骤实现:
步骤1)查找键代码:
$ xmodmap -pke | grep "h H h H"
keycode 43 = h H h H hstroke Hstroke hstroke
$ xmodmap -pke | grep "j J j J"
keycode 44 = j J j J dead_belowdot dead_abovedot dead_belowdot
$ xmodmap -pke | grep "k K k K"
keycode 45 = k K k K kra ampersand kra
$ xmodmap -pke | grep "l L l L"
keycode 46 = l L l L lstroke Lstroke lstroke
$
$ xmodmap -pke | grep "odiaeresis" ## search for the diaresis 'ö'
keycode 47 = odiaeresis Odiaeresis odiaeresis Odiaeresis dead_doubleacute dead_belowdot dead_doubleacute
$ xmodmap -pke | grep "adiaeresis" ## search for the diaresis 'ä'
keycode 48 = adiaeresis Adiaeresis adiaeresis Adiaeresis dead_circumflex dead_caron dead_circumflex
$ ## as we can see the keycodes are: h=43, j=44, k=45, l=46, ö=47, ä=48
根据 ubuntuusers.de/Xmodmap/ 重新映射键的语法如下:
$ xmodmap -e "keycode <keycode> = <key1> <key2> <key3> <key4> <key5> <key6>"
<key1> ... <Key>
<key2> ... <Shift-Key>
<key3> ... <Alt-Key>
<key4> ... <Shift-Alt-Key>
<key5> ... <AltGr-Key> (at least by Unity)
<key6> ... <Shift-AltGr-Key> (at least by Unity)
第2步)根据您的需要映射按键:
$ ## 1 2 3 4 5 6
$ xmodmap -e "keycode 43 = h H NoSymbol NoSymbol Left NoSymbol"
$ xmodmap -e "keycode 44 = j J NoSymbol NoSymbol Down NoSymbol"
$ xmodmap -e "keycode 45 = k K NoSymbol NoSymbol Up NoSymbol"
$ xmodmap -e "keycode 46 = l L NoSymbol NoSymbol Right NoSymbol"
$ ## 1 2 3 4 5
$ xmodmap -e "keycode 47 = odiaeresis Odiaeresis NoSymbol NoSymbol Home"
$ xmodmap -e "keycode 48 = adiaeresis Adiaeresis NoSymbol NoSymbol End"
问题:但是,当我尝试将其映射到 [Alt] 而不是 [AltGr] 时什么也没有发生,也就是说,我的光标既没有按照我想要的方向移动,也没有打印任何字符。
$ ## 1 2 3 4 5 6
$ xmodmap -e "keycode 43 = h H Left NoSymbol NoSymbol NoSymbol"
$ xmodmap -e "keycode 44 = j J Down NoSymbol NoSymbol NoSymbol"
$ xmodmap -e "keycode 45 = k K Up NoSymbol NoSymbol NoSymbol"
$ xmodmap -e "keycode 46 = l L Right NoSymbol NoSymbol NoSymbol"
重新映射这些键的主要原因是为了避免在使用 ATOM 文本编辑器时总是将右手移到箭头键上。因此,我希望能够像在 vim 中或在 ranger 中使用 hjkl 进行导航一样在 Atom 中导航。
提前感谢你的帮助!
答案1
我目前正在使用 xubuntu 16.0.4,之前遇到过类似的问题。我的解决方案是在运行任何命令之前先运行以下xmodmap
命令:
setxkbmap -layout us -variant altgr-intl -option nodeadkeys
您可能需要调整参数以适合您的键盘布局。
答案2
基于这个答案,第三个键实际上是一个Mode_switch
默认未设置的键
这是我在 Pop!_OS 21.04 上使用的完整解决方案
#########################
## add `alt` + `h/j/k/l` => left/up/down/right - per vim bindings
## - https://shellhell.wordpress.com/2012/01/31/hello-world/
## - https://askubuntu.com/questions/1025765/how-to-map-alt-hjkl-keys-to-arrow-keys
## - https://askubuntu.com/questions/465924/how-to-map-modifier-hjkl-to-arrow-key-functionality
#########################
xmodmap -e "keycode 64 = Mode_switch" # set Alt_l as the "Mode_switch"
xmodmap -e "keycode 43 = h H Left H" # h
xmodmap -e "keycode 44 = j J Down J" # j
xmodmap -e "keycode 45 = k K Up K" # k
xmodmap -e "keycode 46 = l L Right L" # l
和如果你把这些放在你的~/.profile
,它们将在启动时设置