2

Is there any way to customize your keyboard to set Shift+Spacebar+SomeLetter as an alternative for arrow keys? When editing text, I either use a mouse or arrow keys to take the cursor to a particular location within some line. Both methods are very restrictive as they make me lose my focus and slow me down.

If I am correct, using Shift+Spacebar has no particular allocation and it just prints the typical space. Combinations of Ctrl, Shift and Alt are often assigned to some other tasks. So it is good to be able to define such a shortcut globally. Is it possible (and do you recommend) to do that? I use Ubuntu 18.04 and I know how to set global commands for applications/programs, but I do not know how to accomplish this job (if possible).

This is how I can add shortcuts in Ubuntu.

enter image description here

  • What editor are you using? Have you considered learning Vim? vi.stackexchange.com – Wildcard Sep 14 '18 at 1:52
  • 1
    Cross posting (posting the exact same question on multiple Stack Exchange sites) is strongly discouraged. I recommend you delete one or the other of the two questions. – Wildcard Sep 14 '18 at 1:54
  • I use Visual Studio Code. It is the first editor I have ever used for programming. I just started to learn working with texteditors. – Opt Sep 14 '18 at 1:55
  • If you can set "global" desktop shortcuts, can you set one to send an arrow key? – Xen2050 Sep 14 '18 at 1:55
  • Thanks, I did not know that. I will remove the other one. – Opt Sep 14 '18 at 1:55
2

Instead of Shift + Spacebar, I used Alt Gr.

Based on the accepted answer to this question, I created a keyboard layout based in the English (UK). If your keyboard is not English UK you might have to change the key codes in the file. This keyboard layout maps the arrow keys to

  • alt gr + s = left
  • alt gr + d = down
  • alt gr + f = right
  • alt gr + e = up
  • alt gr + t = prev page
  • alt gr + v = next page
  • alt gr + a = home
  • alt gr + g = end
  • alt gr + z = backspace
  • alt gr + w = delete
  • alt gr + q = escape
  • alt gr + r = insert

It also maps numbers to the right hand:

  • alt gr + n = 0
  • alt gr + m = 1
  • alt gr + , = 2
  • alt gr + . = 3
  • alt gr + j = 4
  • alt gr + k = 5
  • alt gr + l = 6
  • alt gr + u = 7
  • alt gr + i = 8
  • alt gr + o = 9

Copy the following text into a new file to /usr/share/X11/xkb/symbols/aa

// based on a keyboard map from an 'xkb/symbols/gb' file

default  partial alphanumeric_keys
xkb_symbols "mylayout" {

// Describes the differences between a very simple en_US
// keyboard and a very simple U.K. keyboard layout defined by
// MyLayout

include "latin"

name[Group1]="MyLayout (UK)";

key <AE02>  { [         2,   quotedbl,  twosuperior,    oneeighth ] };
key <AE03>  { [         3,   sterling, threesuperior,    sterling ] };
key <AE04>  { [         4,     dollar,     EuroSign,   onequarter ] };

key <AC11>  { [apostrophe,         at, dead_circumflex, dead_caron] };
key <TLDE>  { [     grave,    notsign,          bar,          bar ] };

key <BKSL>  { [numbersign, asciitilde,   dead_grave,   dead_breve ] };
key <LSGT>  { [ backslash,        bar,          bar,    brokenbar ] };

key <AD01> {    [     q,    Q,    Escape,       Adiaeresis ]    };
key <AD02> {    [     w,    W,    Delete,            Aring ]    };
key <AD03> {    [     e,    E,    Up,           Eacute ]    };
key <AD04> {    [     r,    R,    Prior,       registered ] };
key <AD05> {    [     t,    T,    Prior,            THORN ] };
key <AD06> {    [     y,    Y       ]   };
key <AD07> {    [     u,    U,    7,           Uacute ] };
key <AD08> {    [     i,    I,    8,           Iacute ] };
key <AD09> {    [     o,    O,    9,           Oacute ] };
key <AD10> {    [     p,    P       ]   };
key <AD11> {    [ bracketleft,  braceleft   ]   };
key <AD12> {    [ bracketright, braceright  ]   };

key <AC01> {    [     a,    A,    Home,           Aacute ]  };
key <AC02> {    [     s,    S,    Left,          section ]  };
key <AC03> {    [     d,    D,    Down,              ETH ]  };
key <AC04> {    [     f,    F,    Right,                F ] };
key <AC05> {    [     g,    G,    End,                G ]   };
key <AC06> {    [     h,    H       ]   };
key <AC07> {    [     j,    J,    4,                J ] };
key <AC08> {    [     k,    K,    5,               OE ] };
key <AC09> {    [     l,    L,    6,         Ooblique ] };
key <AC10> {    [ semicolon,    colon,     ntilde,           Ntilde ]   };
key <AC11> {    [ apostrophe,   at,  dead_acute, dead_diaeresis ]   };

key <AB01> {    [     z,    Z,    BackSpace,               AE ] };
key <AB02> {    [     x,    X,    Insert,                X ]    };
key <AB03> {    [     c,    C       ]   };
key <AB04> {    [     v,    V,    Next,                V ]  };
key <AB05> {    [     b,    B,    Next,                B ]  };
key <AB06> {    [     n,    N,    0,           Ntilde ] };
key <AB07> {    [     m,    M,    1,               mu ] };
key <AB08> {    [     comma,    less, 2,           less ]   };
key <AB09> {    [    period,    greater, 3,     greater ]   };
key <AB10> {    [     slash,    question    ]   };

include "level3(ralt_switch_multikey)"
};

Edit the following file: sudo gedit /usr/share/X11/xkb/rules/evdev.xml

before </layoutlist> add this text

<layout>
  <configItem>
    <name>aa</name>
    <shortDescription>MyLayout (UK)</shortDescription>
    <description>MyLayout (UK)</description>
    <languageList>
      <iso639Id>eng</iso639Id>
    </languageList>
  </configItem>
  <variantList/>

Now you have a new keyboard layout with this mapping. Add the layout as the first option in your keyboard input methods and you will be able to use it in the terminal, editors, browser... I have noticed that it doesn't work in some programs like Eclipse. Probably because it has a shorcut defined for them but it works in most places for me.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.