Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 337
John Smith Avatar asked Feb 01 '09 11:02

John Smith


People also ask

Is alt The Meta key?

On many keyboards, the Alt key acts as Meta, so try it. Instead of typing M-a , you can type ESC a .

What is the Meta key in Mac terminal?

What is the Meta Key ? The Meta Key (denoted as M or Meta ) is a modifier key which mean it temporarily modify the normal action of another key when pressed together. Common modifier keys are shift , alt , or control . The meta key was a special modifier key marked with a solid diamond ◆ .

How do I use Home and End key in Mac terminal?

The Home and End keys on a MacBook Pro can be emulated with Fn + ← or f Fn + → . Or when certain settings are changed, with the ⌘ Command key instead of Fn .


2 Answers

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.

like image 163
Joakim Hårsman Avatar answered Oct 02 '22 14:10

Joakim Hårsman


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.

like image 21
Ztyx Avatar answered Oct 02 '22 13:10

Ztyx