With the Germany keyboard layout you need to press ALT aka M to reach certain character one needs for programming C,C++, Java, JS, etc. For instance to reach square brackets [, ] you need to press M-5 or M-6. But when I press alt-5 (M-5) on my Apple Powerbook keyboard my Emacs/Spacemacs responds: No window numbered 5.

What would be a good way to either remap another key like fn as Meta-key or change the keyboard layout on my Macbook Pro for some characters.

3 Answers 3


I have run into this issue before - also trying to use Emacs on OS X with a German keyboard for (C/C++) programming. My solution to this issue was to use the Command key as Meta and pass Option through to the OS to be able to pick up the special characters.

I use the following commands:

(setq mac-command-modifier 'meta mac-option-modifier 'none default-input-method "MacOSX")

I've blogged about this, and you can find the blog post that's a little more in depth over here.

  • I successfully verified your solution, after I found a more detailed description and a different implementation of the same solution at the EmacsWiki. The suggested solution there looks like this: ;; Best option in Emacs 23 is to revert to Emacs 22 settings (alt is alt, cmd is meta) with this snippet: (setq mac-option-key-is-meta nil) (setq mac-command-key-is-meta t) (setq mac-command-modifier 'meta) (setq mac-option-modifier nil) Commented May 16, 2017 at 8:13

To change the meta key you can look at the variables ns-command-modifier, ns-option-modifier, ns-control-modifier, ns-right-command-modifier, ns-right-option-modifier, ns-right-control-modifier. On some versions of Emacs these will be mac- instead of ns-.

I have mine set up so that the left alt key is emacs meta and the right alt key generates the mac native keys — try setting ns-right-option-modifier to either 'none or nil.

The other thing you can try is use key-translation-map:

(define-key key-translation-map [(meta ?5)] [?\[])
(define-key key-translation-map [(meta ?6)] [?\]])

I had a related situation on my Windows 10 computer using Emacs 26.1, and a Norwegian keyboard layout. I'm used to using CTRL+Alt and one of the number keys to access brackets, but it didn't work in Emacs (it ended up mass-adding characters instead).

amitp's answer got me started, and I ended up adding this to the .emacs file:

(define-key key-translation-map [(control meta ?7)] [?\{])
(define-key key-translation-map [(control meta ?8)] [?\[])
(define-key key-translation-map [(control meta ?9)] [?\]])
(define-key key-translation-map [(control meta ?0)] [?\}])

On my keyboard, brackets are located on 7-0 using CTRL+Alt or Alt Gr. Alt Gr for brackets works out of the box, but it's (in my opinion) harder to type than using CTRL+Alt. For other keyboard layouts (i.e. German), it's enough just replacing the number with the appropriate number corresponding to the key used for brackets. It's also possible to remove either control or meta to just use one of the keys.

This should work on Mac and Linux as well, though I can't confirm if it works on a Mac because I don't have one.

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.