15

I am a long time Mac user and I'm now using a Ubuntu machine for development, and while I'm more or less used to a lot of the keyboard shortcuts, one thing I can't get used to is using the 'Home' and 'End' keys to move around lines of text. On a Mac you use "Command + right arrow" to go to the end of a line and "Command + left arrow" to go to the beginning.

Is there a way to enable this kind of functionality in Linux?

I'm not sure if this would be considered remapping, keyboard shortcuts, or what...

3 Answers 3

7

Using xmodmap (some hints) you can rebind keys for the whole window system. The following approach will deliver what you want, but with side effects :(

Try it out in a terminal window first:

  1. Let the left Alt key be the so called Mode_switch:

    1. Assign the key the Mode_switch key sym:

      xmodmap -e 'keycode  64 = Mode_switch Meta_L Alt_L Meta_L'
      
    2. (Normally: Make sure that Mode_switch is assigned to one of the mod1-5 modifier keys, but this is already the case in Ubuntu)

  2. Modify the third row of the Left and Right keys

    xmodmap -e 'keycode 113 = Left NoSymbol Home'
    xmodmap -e 'keycode 114 = Right NoSymbol End'
    

As is the changes are kept until you log out. If you wish to keep it permanently put the following into a file ~/.Xmodmap:

keycode  64 = Mode_switch Meta_L Alt_L Meta_L
keycode 113 = Left NoSymbol Home
keycode 114 = Right NoSymbol End

However be warned that this overrides the normal function of your Alt key (accessing menu, Alt-Tab etc.) :(

I am not an expert in xmodmap & Co, though. Maybe someone else knows how to fix this. I really like Ubuntu and Linux in general, but this whole keyboard stuff is unnecessarily complicated and sorrowly broken :-<

3
  • <3 Thank you! BTW, on Ubuntu 18.04, it seems Super+Tab works like Alt+Tab Commented Mar 19, 2019 at 8:41
  • 1
    What does overwrites the normal function of your alt key mean. Are you saying the behavior of Alt is also changed when not pressed in combination with the left and right keys. (In that case that seems very impractical and probably not a real solution.)
    – Kvothe
    Commented Nov 17, 2020 at 15:55
  • @seya thank you. I managed to map right alt + arrow for start/end of lines and highlights, but any idea how you can alt+backspace to delete the full line as well like in Mac? The only thing missing!!
    – gstlouis
    Commented Apr 16 at 1:26
5

This is specifically for sublime text, but for anyone searching for a way to remap alt and the arrow keys to behave like on a mac might stumble across this answer like I have. In sublime, open Preferences > Key Bindings - User and add the following between the square brackets.

{ "keys": ["alt+left"], "command": "move_to", "args": {"to": "bol", "extend": false} },
{ "keys": ["alt+right"], "command": "move_to", "args": {"to": "eol", "extend": false} }

now, at least you have a useful text editor with proper behaving alt + left and right arrows! Hope this helped a little bit.

1

For programs that use readline (e.g. bash) you can edit ~/.inputrc to bind beginning-of-line and end-of-line to the appropriate sequence. GUI widget toolkits have their own bindings, and you'll have to find the appropriate bits and pieces for them, assuming it's possible at all (GTK+ 2.x).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .