Imagine that you change your keyboard layout. You have to spend time training your muscles to find the keys that you want to type, this is already hard enough.

But you will also have to spend time training your muscles to find the keys that you want to enter as part of shortcuts, which is ridiculous (you have usually chosen these keys because they are easy to reach, not because of their letter*).

Is there a way to have these key definitions not move around when you change your keyboard layout?

For example if I'm in azerty, and I want to learn qwerty, I would like to have beginning-of-line remapped from C-a to C-q, so that it stays where it is on my keyboard (first key right of TAB).

As I understand it, it is partially implemented through input methods, but it takes the opposite way: it changes the way emacs interprets input characters for text. But it won't work if you want to change your keyboard layout system-wide, for example.

I understand that there are lots of ways to define key bindings, but for example, I would deem acceptable a solution that would take care of all key bindings converted from human strings with the kbd function.

*. It is not true for certain keys that are less often used. For example, the C-c map of most major modes use key names that are easy to remember, rather than easy to reach. As a bonus question, it would be nice to be able to preserve (remap so that the physical key doesn't move) some keybindings and move (don't remap, the letter associated to the key doesn't change) some others. The user could select one option or the other by using two different functions instead of kbd when defining his keybindings.

  • 1
    If you can find a solution that detects a particular keyboard layout from within Emacs, then you can remap programmatically based on that detection. There is a related question with no correct answer, entitled Emacs determining keyboard layout: stackoverflow.com/questions/7813648/…
    – lawlist
    Jun 5, 2015 at 14:20
  • @lawlist I did not have the "frequently switching" scenario in mind, at least not frequently enough that changing an option in the init file every time it happens is unreasonable. Sure auto-detection would be even nicer, but if you have a solution requiring that the user informs emacs about his keymaps, I'd be glad to accept it.
    – T. Verron
    Jun 17, 2015 at 5:35
  • @T.Verron am pretty sure the answer is you can't, with plain GNU emacs. You could use a emacs keybinding package that uses the same shortcut position regardless of current keyboard layout. (ergoemacs-mode does that, but it's not the GNU Emacs default keyding) I'm thinking evil-mode might also. Basically, the keybinding package needs to provide a layer.
    – Xah Lee
    Jul 17, 2015 at 7:32

1 Answer 1


As far as I understand your question the key-translation-map seems like a good soultion for your problem. For example if you would like to have C-q acting like C-a as in your example, you would define the following:

  (define-key key-translation-map (kbd "C-q") (kbd "C-a"))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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