简体   繁体   English

如何更改 Emacs 中的元键?

[英]How to change the meta key in Emacs?

I've just started to put in the time to get to learn emacs.我刚刚开始花时间学习 emacs。 By default my meta key is bound to Esc, and I'm finding that really inconvenient.默认情况下,我的元键绑定到 Esc,我发现这真的很不方便。 I read somewhere however that it's not a good idea to change the binding to Alt.但是,我在某处读到将绑定更改为 Alt 并不是一个好主意。 Is that true?这是真的吗? If not, how could I go about doing that?如果没有,我怎么能去做呢?

It's bound to Alt by default for me, and I have no problems with that.它默认绑定到 Alt 对我来说,我对此没有任何问题。 Are you on a Mac perhaps?你可能在 Mac 上吗? 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--eg, I think changing it in the terminal would be different than changing it on one of the windowed varieties.如果您使用的是 mac,更改密钥的方式可能会因您使用的 Emacs 版本而异——例如,我认为在终端中更改它与在其中一个窗口版本上更改不同。

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 .另一件事要尝试: http: //www.jwz.org/xkeycaps/ 用这个查看键盘布局,看看是否有任何键分配给Meta If not, try assigning it;如果没有,请尝试分配它; otherwise try changing it.否则尝试改变它。 I haven't actually tried this, but it looks promising.我还没有真正尝试过这个,但看起来很有希望。

If you are using a Mac, you can follow the directions from here :如果您使用的是 Mac,则可以按照此处的说明进行操作

"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." “如果您不想使用 Esc 键,您可以指定一个键用作 Meta。要指定一个 Meta 键,请选择编辑器首选项对话框的仿真选项卡。”

You can then select to use Alt or Command as your Meta key.然后您可以选择使用 Alt 或 Command 作为您的 Meta 键。

I'm guessing that you're on Mac, because I had the same problem.我猜你在 Mac 上,因为我有同样的问题。 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.我使用的是 OS X 10.11.5,所以我不知道旧版本的终端。 I imagine that it would be similar.我想它会是相似的。

I had to do this for emacs while remotely connected to my raspberry pi.我必须在远程连接到我的树莓派时为 emacs 执行此操作。

  1. Go to terminal.去终端。

  2. type:类型:

     xmodmap -e "keysym Alt_L = Meta_L Alt_L"

This was suggested in xmodmap's manual这是在 xmodmap 的手册中建议的

man xmodmap

Hope that helps :) I'm pretty new to this though so someone else may want to comment.希望有所帮助:) 我对此很陌生,所以其他人可能想发表评论。

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.对我来说,在我的 mac 上,它默认绑定到 Alt,但我发现它很烦人,因为 Alt 用于 Mac 上的一些特殊字符。 I added these lines on my .emacs我在我的 .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)因此,在您的情况下,您必须将其添加到 .emacs 中(我尝试了此解决方案,并且对我有用)

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM