macos 使 iTerm 以与其他操作系统相同的方式翻译“元密钥”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/196357/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 05:56:40  来源:igfitidea点击:

Making iTerm to translate 'meta-key' in the same way as in other OSes

macoscommand-linekeyboard-shortcuts

提问by ejel

In bash shell with emacs key-binding, you can use key combination like M-f, M-b to move one word forward or backward on the shell prompt respectively. Usually, the meta key is mapped to Alt key on Windows and Linux. However, in iTerm, I could not find a way to map this meta key to either Option or Command key on my MacBook Pro.

在带有 emacs 键绑定的 bash shell 中,您可以使用 Mf、Mb 等组合键分别在 shell 提示符下向前或向后移动一个单词。通常,元键映射到 Windows 和 Linux 上的 Alt 键。但是,在 iTerm 中,我找不到将此元键映射到 MacBook Pro 上的 Option 或 Command 键的方法。

It seems that in OS X, the meta key is by default mapped to ESC key. So you can use ESC-f, ESC-b on iTerm. However, ESC key is apparently not practical to use. In addition, iTerm does have option that allow you to modifier mapping for the meta key (Bookmarks > Profiles > Keyboard Profiles > Global > Option Key as...), this setting does not seem to work at all.

似乎在 OS X 中,元键默认映射到 ESC 键。所以你可以在 iTerm 上使用 ESC-f、ESC-b。但是,ESC 键显然不实用。此外,iTerm 确实有允许您修改元键映射的选项(书签 > 配置文件 > 键盘配置文件 > 全局 > Option Key as...),此设置似乎根本不起作用。

Therefore, if anyone know what is the solution to this problem, please let me know.

因此,如果有人知道此问题的解决方案是什么,请告诉我。

I have upgraded to the latest release, 0.9.6.1012, and this behavior is still persist.

我已升级到最新版本 0.9.6.1012,但这种行为仍然存在。

Edit:Some clarification to my question. The key-binding I'm talking about is for bash shell, not in emacs. It just happens that, by default, bash shell also use the same key-binding as emacs.

编辑:对我的问题的一些澄清。我正在谈论的键绑定是针对 bash shell,而不是在 emacs 中的。碰巧的是,默认情况下,bash shell 也使用与 emacs 相同的键绑定。

回答by

Cmd+., Profiles, Keysand choose Left option Key acts as: +Esc.

Cmd+., Profiles,Keys并选择Left option Key acts as: +Esc

Works for me in emacs, though I'm not sure if it will have any other undesirable effects.

在 emacs 中对我有用,但我不确定它是否会产生任何其他不良影响。

回答by Dag H?idahl

Go to Bookmarks > Manage Profiles. Then select Keyboard Profiles > Globaland choose Option Key as Meta. This works for me in version 0.9.6.1201.

转至书签 > 管理个人资料。然后选择键盘配置文件 > 全局并选择Option Key 作为 Meta。这在 0.9.6.1201 版本中对我有用。

回答by Dag H?idahl

In Menu bar Iterm2 => Preferences => Profiles choose the keys tab and select

在菜单栏中 Iterm2 => Preferences => Profiles 选择键选项卡并选择

left Option key act as +Esc

左 Option 键充当 +Esc

enter image description here

在此处输入图片说明

worked for me as well in irssi.

在 irssi 中也对我来说有效。

回答by nyenyec

I couldn't get the Alt key working either but there is a workaround that makes it at least function for word navigation via the cursor keys:

我也无法让 Alt 键工作,但有一种解决方法可以使其至少通过光标键进行单词导航:

Skip to Next or Previous Word in iTerm Using Alt / Option + Left or Right Arrow Keys

使用 Alt / Option + 向左或向右箭头键跳到 iTerm 中的下一个或上一个单词

回答by ches

Going all zombie resurrection here, but for sake of posterity --

在这里进行所有僵尸复活,但为了后代——

This postgot it working as you desire for me, for M-b and M-f, while keeping 'Option Key as Meta' set so you don't sacrifice a modifier (I have vim mappings using meta, personally).

这篇文章让它按照你对 Mb 和 Mf 的期望工作,同时保持“Option Key as Meta”设置,这样你就不会牺牲一个修饰符(我个人有使用元的 vim 映射)。

In summary, in your Global Keyboard Profile, add two new mappings with settings:

总之,在您的全局键盘配置文件中,添加两个带有设置的新映射:

  1. Key as hex code, value of 62 for b, 66 for f (man ascii)
  2. Modifier as Option
  3. Action as send escape sequence, value b or f
  1. 键为十六进制代码,b 值为 62,f ( man ascii)值为 66
  2. 修饰符作为选项
  3. 操作作为发送转义序列,值 b 或 f

The only thing I still miss from Terminal.app is Opt-Backspaceto delete by word. There are other workarounds for that, but I'm just trying to train myself to use Ctrl-w.

我仍然想念 Terminal.app 的唯一一件事就是Opt-Backspace逐字删除。还有其他解决方法,但我只是想训练自己使用Ctrl-w.

回答by George

It's easier in iTerm2. Go to preferences->bookmark->keyboard and select Option sends +ESC. In iTerm2 you can configure the left and right option keys separately, so remember to change both if that's what you want. Link for iTerm2: http://sites.google.com/site/iterm2home/

在 iTerm2 中更容易。转到首选项-> 书签-> 键盘并选择选项发送 +ESC。在 iTerm2 中,您可以分别配置左右选项键,因此如果您想要,请记住同时更改两者。iTerm2 的链接:http://sites.google.com/site/iterm2home/

回答by George

Go to Bookmarks > Manage Profiles. Then select Keyboard Profiles > Global and choose Option Key as +ESC.

转至书签 > 管理个人资料。然后选择键盘配置文件 > 全局并选择选项键为 +ESC。

Works in iTerm Build 0.9.5.0611 & Build 0.9.6.20090415

适用于 iTerm Build 0.9.5.0611 & Build 0.9.6.20090415

回答by holms

I found some solution on stackoverflow also, just go to keyboard profile and in "Global" change "Option key as" +ESC

我也在 stackoverflow 上找到了一些解决方案,只需转到键盘配置文件并在“全局”中将“选项键更改为”+ESC

that works for me perfectly =) btw some iterm patch exists also look here: http://www.emacswiki.org/emacs/EmacsForMacOS

这对我来说非常适用 =) 顺便说一句,也存在一些 iterm 补丁,请看这里:http://www.emacswiki.org/emacs/EmacsForMacOS

回答by M. Demianchuk

I use iTerm2, and for me, this answerjust partially solved my problem:

我使用iTerm2,对我来说,这个答案只是部分解决了我的问题:

Cmd+,=> Profiles=> Keysand choose Left option Key acts as: +Esc.

enter image description here

Cmd+ ,=> Profiles=> Keys并选择 Left option Key 作为:+Esc

在此处输入图片说明

In addition to that, I had to go to Cmd+,=> Profiles=> Keysand in the Key Mappingslist find both Key Combinations: enter image description hereand enter image description here, double click them and change their shortcuts to the following:

除此之外,我必须转到Cmd+ ,=> Profiles=> Keys并在Key Mappings列表中找到两个Key Combinations:在此处输入图片说明在此处输入图片说明,双击它们并将它们的快捷方式更改为以下内容:

enter image description here

在此处输入图片说明

enter image description here

在此处输入图片说明

*Make sure to select Send Escape Sequenceaction.

*确保选择发送转义序列操作。

回答by Mikhail at YugaByte

Here is what worked for me: Bookmarks > Manage Profiles > Keyboard Profiles > Global/xterm > Option Key as +Esc. With this, I can use Option+Enter in Midnight Commander and the currently selected file/directory name shows up in the command string, as it should. Option Key as Meta did not work for me. My build of iTerm is 0.10.

这对我有用:书签 > 管理配置文件 > 键盘配置文件 > 全局/xterm > Option Key as +Esc。有了这个,我可以在 Midnight Commander 中使用 Option+Enter 并且当前选择的文件/目录名称显示在命令字符串中,这是应该的。Option Key as Meta 对我不起作用。我的 iTerm 版本是 0.10。