Friday, May 3, 2013

HJKL for direction keys in Ubuntu

Hi,

I recently came back to Ubuntu for some developing works. One thing I really miss from my Macbook Pro is the global remap setting of the very handy HJKL keys and some other shortcuts.

So I decide to replicate it.


Actually, there are more than one kinds of Shift key in the world, the one we used everyday should be literally called as Level2_Shift. If you would open your keyboard remap file by this terminal command:

vi /usr/share/X11/xkb/symbols/us

You would see how this actually works. For each key, the original mapping to the alphabet or function is defined, in addition, a second mapping to the capital letters are defined as well.

    key <AE06> {        [         6,    asciicircum     ]       };

The ^ key was defined as Level2, and the Shift key we used normally would map the keystroke to ^ rather than '6', the level 1 stuff.

So the basic idea would be to make the Caps key itself as a Level3_Shift, and make the directional key as the Level3 function of HJKL.

Thus:

I would add such a few lines in the first part of the file ( with sudo ):

sudo vi /usr/share/X11/xkb/symbols/us

And the lines are:

key <AC06> {    [       h, H, Left      ]       };
key <AC07> {    [       j, J, Down      ]       };
key <AC08> {    [       k, K, Up        ]       };
key <AC09> {    [       l, L, Right     ]       };

key <CAPS> {[ISO_Level3_Shift]};

//---------------------------------------------------------------------

Save the modification to disk using command ":wq", and log off, log on

You should notice the caps won't work as before. And the directional keys are just more handier.

If you still want the Original caps back, you may consider using Caps + A as the original Caps, they are close to each other and are easy to press as one key:

Change one more line : {[ a, A, CAPS]};

Happy HJLK