OS X Terminal: Meta key + alt functionality at the same time

37,950

Solution 1

Think about using a full featured Emacs for Mac OS X. I use Carbon Emacs but I believe others (say Aqua Emacs or X11 Emacs) would do the trick.

If you insist on using Emacs in a terminal you can use the C-x 8 prefix as a compose key. Try C-x 8 C-h to get a list of possibilities.

See http://www.emacswiki.org/emacs/EmacsForMacOS

Solution 2

I use a Swedish keyboard in Mac OS X and use the following setup for Emacs.app:

First I have KeyRemap4MacBook installed and I have it setup to change the left Option key to Command.

I then have the following in my .emacs:

(setq mac-option-modifier 'none)
(setq mac-command-modifier 'meta)

This makes Emacs treat command as Meta and ignore Option. Since the left Alt/Option key is remapped to command, this makes it work lite meta while the right Alt/Option key still works for entering special characters like @ [] and {}.

App specific Mac shortcuts like Cmd+C and Cmd+V no longer work, but global shortcuts like Cmd+space for Spotlight and Cmd+Tab for app switching do.

Update: If you use iTerm2 as a Terminal, that has support for mapping only the left Alt/Option key to meta, which means you can still use the right AltGr/Option key for entering special characters. This also means you can use meta as normal inside Emacs running in the iTerm2 terminal.

Solution 3

I have a Swedish keyboard on my Mac and I'm using Aquamacs. Adding the two lines (attribution goes to Joakim Hårsman)

(setq mac-option-modifier 'none)
(setq mac-command-modifier 'meta)

in .emacs (and restarting Aquamacs) did the trick for me.

Solution 4

with iTerm2 you can map the left option key to ESC/meta and leave the mapping of the right option key to "normal". This way you can use the right option key to type accents etc.

iTerm2 preferences

Solution 5

This is an old post but adding an alternatives for Robots to find. I borrowed a couple of files from Aquamacs(emulate-mac-keyboard-mode.el, aquamacs-tools.el) that fixes the problem (I have a Italian-Pro keyboard) :

(defun aq-binding (any)
 nil)
(load  "~/.emacs.d/emulate-mac-keyboard-mode.el") ;;  'noerror

this provides:

  • few minor modes (emulate-mac-italian-keyboard-mode, emulate-mac-french-keyboard-mode, mulate-mac-swiss-german-keyboard-mode, etc)
  • a menu to play with all the options provided by Aquamacs

Tested with Emacs-23.3-universal-10.6.6 and seems to work ok for me.

Thanks Aquamacs for this, what about pushing this upstream if not already done.

Share:
37,950
John Smith
Author by

John Smith

Updated on April 09, 2020

Comments

  • John Smith
    John Smith about 4 years

    Is there a way to use an alt / option key as a meta key but still be able to use it to make some characters which need it?

    For example, in my local keyboard layout:

    • @ is alt + 2
    • \ is alt + shift + 7
    • | is alt + 7
    • etc.

    So, if I set alt as a meta key, I can't make those characters anymore. On the other hand, using "press esc, release esc, press a key" to make meta key sequences makes my hands hurt.

    Any Emacs users with international keyboards who have solved this, please give any tips you might have! :)

    Edit:

    It appears that I can set alt as a meta key and then add these kind of settings in inputrc: "\e2": "@" This works in the bash shell but it still won't work with Emacs though, so no good.