iman453
iman453

Reputation: 9535

How to change the meta key in Emacs?

I've just started to put in the time to get to learn emacs. By default my meta key is bound to Esc, and I'm finding that really inconvenient. I read somewhere however that it's not a good idea to change the binding to Alt. Is that true? If not, how could I go about doing that?

Upvotes: 14

Views: 27110

Answers (5)

Nihil
Nihil

Reputation: 11

I had to do this for emacs while remotely connected to my raspberry pi.

  1. Go to terminal.

  2. type:

    xmodmap -e "keysym Alt_L = Meta_L Alt_L"
    

This was suggested in xmodmap's manual

man xmodmap

Hope that helps :) I'm pretty new to this though so someone else may want to comment.

Upvotes: 1

kgrimes2
kgrimes2

Reputation: 136

I'm guessing that you're on Mac, because I had the same problem. This is how I fixed it:

  1. Open Terminal
  2. Open up the preferences
  3. Open up the "Profiles" tab and choose the "Keyboard" tab with your current profile selected
  4. Below the long scroll box are a couple check boxes. Check "Use Option as Meta key."

I'm using OS X 10.11.5, so I don't know about older versions of Terminal. I imagine that it would be similar.

Upvotes: 3

Laurent Hayez
Laurent Hayez

Reputation: 103

For me, on my mac, it was bound to Alt by default, but I found it anoying because Alt is used for some special characters on Mac. I added these lines on my .emacs

(setq mac-function-modifier 'meta)
(setq mac-option-modifier nil)

Thus in your case, you would have to add this in your .emacs (I tried this solution, and it worked for me)

(setq mac-option-modifier 'meta) ; set alt-key to meta
(setq mac-escape-modifier nil) ; set esc-key to nil

Upvotes: 3

Tikhon Jelvis
Tikhon Jelvis

Reputation: 68152

It's bound to Alt by default for me, and I have no problems with that. Are you on a Mac perhaps? There it is bound to one of the other keys like option.

If you are on a mac, the way to change the key will probably vary based on which version of Emacs you're using--e.g., I think changing it in the terminal would be different than changing it on one of the windowed varieties.

Another thing to try: http://www.jwz.org/xkeycaps/ Look through the keyboard layout with this and see if any key is assigned to Meta. If not, try assigning it; otherwise try changing it. I haven't actually tried this, but it looks promising.

Upvotes: 8

Alan Geleynse
Alan Geleynse

Reputation: 25139

If you are using a Mac, you can follow the directions from here:

"If you do not want to use the Esc key, you can specify a key to use as Meta. To specify a Meta key, select the Emulation tab of the Editor Preferences dialog."

You can then select to use Alt or Command as your Meta key.

Upvotes: 5

Related Questions