macos OS X 终端:同时具有 Meta 键 + alt 功能
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/500602/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
OS X Terminal: Meta key + alt functionality at the same time
提问by John Smith
Is there a way to use an alt/ optionkey as a meta key but still be able to use it to make some characters which need it?
有没有办法使用alt/option键作为元键,但仍然能够使用它来制作一些需要它的字符?
For example, in my local keyboard layout:
例如,在我的本地键盘布局中:
@
is alt+ 2\
is alt+ shift+ 7|
is alt+ 7- etc.
@
是alt+2\
是alt+ shift+7|
是alt+7- 等等。
So, if I set altas 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.
所以,如果我设置alt为元键,我就不能再制作这些字符了。另一方面,使用“按 esc,释放 esc,按一个键”来制作元键序列会让我的手受伤。
Any Emacs users with international keyboards who have solved this, please give any tips you might have! :)
任何使用国际键盘的 Emacs 用户已经解决了这个问题,请提供您可能有的任何提示!:)
Edit:
编辑:
It appears that I can set altas 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.
看来我可以设置alt为元键,然后在 inputrc 中添加这些类型的设置:"\e2": "@"
这在 bash shell 中有效,但它仍然无法与 Emacs 一起使用,所以不好。
采纳答案by kmkaplan
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.
考虑在 Mac OS X 上使用功能齐全的 Emacs。我使用 Carbon Emacs,但我相信其他人(比如 Aqua Emacs 或 X11 Emacs)可以解决问题。
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.
如果您坚持在终端中使用 Emacs,您可以使用C-x 8
前缀作为组合键。尝试C-x 8 C-h
获取可能性列表。
回答by Joakim H?rsman
I use a Swedish keyboard in Mac OS X and use the following setup for Emacs.app:
我在 Mac OS X 中使用瑞典语键盘,并为 Emacs.app 使用以下设置:
First I have KeyRemap4MacBookinstalled and I have it setup to change the left Option key to Command.
首先,我安装了KeyRemap4MacBook,并将其设置为将左 Option 键更改为 Command。
I then have the following in my .emacs:
然后我的 .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 {}.
这使得 Emacs 将命令视为元并忽略选项。由于左 Alt/Option 键被重新映射到命令,这使得它可以在 lite meta 中工作,而右 Alt/Option 键仍然可以用于输入特殊字符,如 @ [] 和 {}。
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.
应用程序特定的 Mac 快捷方式,如 Cmd+C 和 Cmd+V 不再有效,但全局快捷方式,如用于 Spotlight 的 Cmd+space 和用于应用程序切换的 Cmd+Tab 可以。
Update:If you use iTerm2as 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.
更新:如果您使用iTerm2作为终端,它支持仅将左 Alt/Option 键映射到元,这意味着您仍然可以使用右 AltGr/Option 键输入特殊字符。这也意味着您可以在 iTerm2 终端中运行的 Emacs 中正常使用 meta。
回答by Ztyx
I have a Swedish keyboard on my Mac and I'm using Aquamacs. Adding the two lines (attribution goes to Joakim H?rsman)
我的 Mac 上有一个瑞典语键盘,我使用的是 Aquamacs。添加两行(归因于 Joakim H?rsman)
(setq mac-option-modifier 'none)
(setq mac-command-modifier 'meta)
in .emacs
(and restarting Aquamacs) did the trick for me.
in .emacs
(并重新启动 Aquamacs)对我有用。
回答by Jan Berkel
回答by bendin
Two work-arounds I use:
我使用的两种解决方法:
- I use xterm running under X11.app. X11.app uses the command key as meta.
- When running emacs in Terminal.app, I just use the rfc1345 input-method, which allows me to enter all kinds of crazy non-ascii characters without needing an option key.
- 我使用在 X11.app 下运行的 xterm。X11.app 使用命令键作为元。
- 在 Terminal.app 中运行 emacs 时,我只使用 rfc1345 输入方法,它允许我输入各种疯狂的非 ascii 字符而无需选项键。
回答by wilane
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) :
这是一篇旧帖子,但为机器人添加了一个替代方案。我从 Aquamacs( emulate -mac-keyboard-mode.el, aquamacs-tools.el)借了几个文件来解决这个问题(我有一个意大利专业键盘):
(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
- 少数次要模式(emulate-mac-italian-keyboard-mode、emulate-mac-french-keyboard-mode、mulate-mac-swiss-german-keyboard-mode等)
- 使用 Aquamacs 提供的所有选项的菜单
Tested with Emacs-23.3-universal-10.6.6 and seems to work ok for me.
用 Emacs-23.3-universal-10.6.6 测试过,对我来说似乎没问题。
Thanks Aquamacs for this, what about pushing this upstream if not already done.
感谢 Aquamacs 为此,如果尚未完成,如何将其推向上游。
回答by stuntmouse
Check out cmd-key-happy. This little app has worked wonders for me. It allows you to use command as meta, with exceptions that you can configure.
查看 cmd-key-happy。这个小应用程序为我创造了奇迹。它允许您将命令用作元数据,但您可以配置例外。
Author's info follows:
作者信息如下:
This program allows you to swap the command and alt (or option) keys in any application, but in particular Terminal.app.
该程序允许您在任何应用程序中交换命令和 alt(或选项)键,尤其是 Terminal.app。
回答by mach
Special keyboard layout with option deadkey
带有选项死键的特殊键盘布局
My solution to this problem is a special keyboard layout I have written, U.S. custom. It provides an option deadkeythat produces option combos without having to use the physical ? Optionmodifier key. For instance, the character ??? is produced as follows on a normal U.S. keyboard layout:
我对这个问题的解决方案是我编写的特殊键盘布局,美国自定义. 它提供了一个选项死键,无需使用物理? Option修饰键即可生成选项组合。例如,字符??? 在正常的美式键盘布局上生成如下:
- Hit ? Option+c.
- 点击? Option+ c。
The U.S. customkeyboard layout adds a second way of producing ???:
在美国的自定义键盘布局增加了生产???的第二种方式:
- Hit ? Shift+§(the option deadkey), then release it, then hit c.
- 点击? Shift+ §(选项死键),然后释放它,然后点击c。
This works even in Terminal.app when Use option as meta keyhas been checked.
当使用选项作为元键被选中时,这甚至在 Terminal.app 中也有效。
Note that the U.S. custom keyboard layout does two additional things:
请注意,美国自定义键盘布局还有两件事:
- It converts plain §into a ? Composekey (so you could also produce ??? by hitting §, then ,, then c).
- It replaces the CapsLock mapping by a (significantly extended) U.S. Extendedkeyboard layout.
- 它将普通转换§为一个? Compose键(所以你也可以通过点击§、 然后,、 然后 来生成 ??? c)。
- 它用(显着扩展的)美国扩展键盘布局替换了 CapsLock 映射。
Remap option deadkey to right option modifier key
将选项死键重新映射到正确的选项修饰键
If you have a physical ANSI keyboard, then you lack the §key. In that case, I recommend assigning the §key to some other key, for instance to the right ? Optionmodifier key. Install KeyRemap4MacBook, open ~/Library/Application\ Support/KeyRemap4MacBook/private.xml
and paste the following code:
如果您有一个物理 ANSI 键盘,那么您就缺少该§键。在这种情况下,我建议将该§键分配给其他某个键,例如分配给右侧的? Option修饰键。安装KeyRemap4MacBook,打开~/Library/Application\ Support/KeyRemap4MacBook/private.xml
并粘贴以下代码:
<?xml version="1.0"?>
<root>
<item>
<name>Send ISO Section for right Option</name>
<identifier>private.send_iso_section_for_right_option</identifier>
<autogen>--KeyToKey-- KeyCode::OPTION_R, KeyCode::UK_SECTION</autogen>
</item>
<item>
<name>Send Shift+ISO Section for Shift+right Option (keep normal right Option without Shift)</name>
<identifier>private.send_shift_iso_section_for_shift_right_option</identifier>
<autogen>--KeyToKey-- KeyCode::OPTION_R, ModifierFlag::SHIFT_R, KeyCode::UK_SECTION, ModifierFlag::SHIFT_L</autogen>
<autogen>--KeyToKey-- KeyCode::OPTION_R, ModifierFlag::SHIFT_L, KeyCode::UK_SECTION, ModifierFlag::SHIFT_L</autogen>
</item>
</root>
Then, open the KeyRemap4MacBook preference pane, hit ReloadXMLand then select “Send ISO Section for right option”. Now, your ? Right Optionkey is remapped to §, so while the U.S. customkeyboard layout is active, hitting ? Shift+? Right Optionwill give you the option deadkey state (hitting ? Right Optionwithout additional modifiers will give you a deadkey state equivalent to the option modifier.
然后,打开 KeyRemap4MacBook 首选项面板,点击ReloadXML,然后选择“Send ISO Section for right option”。现在,您的? Right Option键被重新映射到§,因此当美国自定义键盘布局处于活动状态时,点击? Shift+? Right Option将为您提供选项死键状态(在? Right Option没有额外修饰符的情况下点击将给您一个等同于选项修饰符的死键状态。
If want to keep ? Right Optionwhen ? Shiftis not pressed (instead of the ? Composekey), then select “Send Shift+ISO Section for Shift+right Option (keep normal right Option without Shift)” in the KeyRemap4MacBook preference pane (instead of “Send ISO Section for right Option”). Like that, only ? Shift+? Right Optionwill produce the option deadkey, while plain ? Right Optionwill continue to work as an option modifier. You can even continue using ? Right Option+? Shiftmodifier combos (for instance ? Right Option+? Shift+c→???) as long as you don't hit ? Shiftfirst.
如果想在未按下? Right Option时保留? Shift(而不是? Compose键),则在 KeyRemap4MacBook 首选项窗格中选择“Send Shift+ISO Section for Shift+right Option(保持正常的右选项而不使用 Shift)”(而不是“Send ISO Section for Shift+right Option)”正确的选项”)。像那样,只有? Shift+? Right Option会产生选项死键,而普通? Right Option将继续作为选项修饰符工作。你甚至可以继续使用? Right Option+? Shift修饰符组合(例如? Right Option+ ? Shift+ c→???),只要你不? Shift先击中。
回答by Westcroft_to_Apse
It's worth thinking about the assumption behind the question. I mean to say that the real problem is making the characters that currently seem to need the option key. This problem can be solved without achieving simultaneous 'meta key + alt functionality'.
值得思考问题背后的假设。我的意思是说,真正的问题是制作当前似乎需要选项键的字符。这个问题可以在不同时实现“元键+ alt功能”的情况下解决。
Let me explain: I have a similar problem. On my UK keyboard, shift-3 is mapped to the pound sign, £, which means that I generally need to hit option-3 to get the very useful # - a real problem in Terminal, where I use option as meta. However, I find most of the above solutions to be a little over-the-top. I don't want to change to another version of Emacs (eg. Aquamacs), to switch to a different Terminal application (eg. iTerm or xterm), or to install a key-remapping application (eg. KeyRemap4MacBook) all for the sake of one symbol! Perhaps that would suit some people, but I thought it was worth pointing out that if the problem is just one character, it can be solved with a nine-character text file.
让我解释一下:我有类似的问题。在我的英国键盘上,shift-3 被映射到英镑符号 £,这意味着我通常需要点击 option-3 来获得非常有用的 # - 在终端中一个真正的问题,我使用选项作为元。但是,我发现上述大多数解决方案都有些过分。我不想更改到另一个版本的 Emacs(例如 Aquamacs),切换到不同的终端应用程序(例如 iTerm 或 xterm),或者安装一个键重映射应用程序(例如 KeyRemap4MacBook),所有这些都是为了一个符号!也许这适合某些人,但我认为值得指出的是,如果问题只有一个字符,则可以使用九个字符的文本文件来解决。
With regard to my personal version of this problem, I find the simplest solution is to create a file called .inputrc
in my home directory, consisting of the following single line:
关于这个问题的个人版本,我发现最简单的解决方案是.inputrc
在我的主目录中创建一个名为的文件,由以下单行组成:
"§": "#"
This re-maps the (to me, quite useless) § that can be found to the left of the 1 on the current Mac keyboard to the (almost indispensable) #. That suits me even better than the default setup, because I can now get # with a single keypress. If there were any other characters I needed to remap, it would just be a matter of adding an extra line for each one.
这将当前 Mac 键盘上 1 左侧的(对我来说,非常无用)§ 重新映射到(几乎必不可少的)#。这比默认设置更适合我,因为我现在可以通过一次按键获得 #。如果我需要重新映射任何其他字符,只需为每个字符添加一行即可。
Anyway, that deals with how to get the missing character in the shell, but if you also want it in Emacs (which you didn't say but is probably the case) then you can add something like this to your .emacs
file (where 35 is the ASCII for the character I happen to want, ie. #):
无论如何,这涉及如何在 shell 中获取丢失的字符,但是如果您也想在 Emacs 中使用它(您没有说但可能是这种情况),那么您可以将这样的内容添加到您的.emacs
文件中(其中 35 是我碰巧想要的字符的 ASCII,即。#):
(global-set-key (kbd "§") 'insert-hash)
(defun insert-hash ()
(interactive)
(insert 35))
It might not be such a neat solution if there were dozens of characters that I routinely wanted to access via the option key, but there aren't.
如果我经常想通过选项键访问几十个字符,这可能不是一个很好的解决方案,但没有。
I hope this helps somebody. As a mere weekend hacker, I ordinarily wouldn't dare post an answer to a question on Stack Overflow...
我希望这对某人有帮助。作为一个纯粹的周末黑客,我通常不敢在 Stack Overflow 上发布问题的答案......
回答by unhammer
The above answers mention ways to enter non-ascii input, but that's not really the problem here. The C-x 8 method lets you enter a bunch of non-ascii, but the problem is that you need the option key on mac just to enter the (ascii) character `|' (vertical bar)!
上面的答案提到了输入非 ascii 输入的方法,但这并不是真正的问题。Cx 8 方法让你输入一堆非ascii,但问题是你需要mac上的option键来输入(ascii)字符`|' (竖条)!
So how do you then enter stuff like M-| (region to shell command) when running emacs in ssh under Terminal.app? No way for it but to use the escape key, since | is option-7 and Terminal.app for some stupid reason won't let you use Cmc as meta :-(
那么你如何输入像 M-| 这样的东西 (区域到 shell 命令)在 Terminal.app 下的 ssh 中运行 emacs 时?没有办法,只能使用转义键,因为 | 是 option-7 和 Terminal.app 出于某种愚蠢的原因不会让你使用 Cmc 作为元 :-(
(If anyone knows of a hack (SIMBL perhaps?) that actually does let Terminal.app use Cmd as meta, I'd be very grateful...)
(如果有人知道实际上确实让 Terminal.app 使用 Cmd 作为元的黑客(也许是 SIMBL?),我将非常感激......)