Ubuntu – How to map [Alt] + [hjkl] keys to arrow keys

xmodmap

I know how to map [AltGr] + [h|j|k|l] keys to arrow keys, like:

[AltGr]+[h] ... [Left]  
[AltGr]+[j] ... [Down]  
[AltGr]+[k] ... [Up]  
[AltGr]+[l] ... [Right]  

[AltGr]+[ö] ... [Home]  
[AltGr]+[ä] ... [End]  

This is possible in two steps:

Step 1) Find the keycodes:

$ 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  

According to
ubuntuusers.de/Xmodmap/
the syntax to remap the keys is the following:

$ 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)

Step 2) Map the keys to your desire:

$ ##                       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"

Problem: However when i try to map it to [Alt] instead of [AltGr] nothing happens, i.e. neither my cursor moves according to my desired direction, nor any characters get print.

$ ##                       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"  

The main reason for remapping those keys is to avoid moving my right hand always to the arrow keys while working in the ATOM text editor. So i want to be able to navigate in atom like in vim or in ranger with hjkl.

Thanks in advance for help!

Best Answer

I am currently using xubuntu 16.0.4 and encountered similar issue before. My solution was to run below first before any xmodmap commands:

setxkbmap -layout us -variant altgr-intl -option nodeadkeys

You may need to adjust the parameters to fit your keyboard layout.