bash Mac OS X 终端 [使用选项作为元键] 覆盖西班牙语键盘中的反斜杠

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

Mac OS X Terminal [Use option as meta key] overrides backslash in spanish keyboard

macosbashterminalmeta-key

提问by nephewtom

I check "Use option as meta key" checkbox in Mac OS X Terminal, because I like to use emacs way of moving between words: M-f & M-b.

我在 Mac OS X 终端中选中“使用选项作为元键”复选框,因为我喜欢使用 emacs 在单词之间移动的方式:Mf 和 Mb。

But if I do that, I can't get the backslash (Option + o; i.e.: Option + key-at-the-left-of-1-in-spanish-keyboard). If I uncheck it, then I can input the backslash, but I don't have M-f & M-b.

但是如果我这样做,我就无法得到反斜杠(Option + o;即:Option + key-at-the-left-of-1-in-spanish-keyboard)。如果我取消选中它,那么我可以输入反斜杠,但我没有 Mf 和 Mb。

Is there a way to get both?

有没有办法同时获得?

回答by ocodo

Not a great solution, but XTerm (running in X11 on OS X) can use CMD as the Meta key.

不是一个很好的解决方案,但 XTerm(在 OS X 上的 X11 中运行)可以使用 CMD 作为 Meta 键。

You might also have some good results from KeyRemap4MacBook.

您也可能从KeyRemap4MacBook获得一些不错的结果。

Just as a side benefit, XTerm should also give you proper terminal mouse interaction, e.g. in Emacs or ncurses based apps.

作为附带的好处,XTerm 还应该为您提供适当的终端鼠标交互,例如在基于 Emacs 或 ncurses 的应用程序中。

回答by Asmus

You will most likely run into a lot more problems with that setup, because Mac OS uses "Alt" as a modifier in a lot of shortcuts. But anyway, including the following line in your ~/.bash_profile will send a backslash if you enter the unicode character "∫" (which is E288AB):

您很可能会在该设置中遇到更多问题,因为 Mac OS 在许多快捷方式中使用“Alt”作为修饰符。但无论如何,如果您输入 unicode 字符“∫”(即 E288AB),在 ~/.bash_profile 中包含以下行将发送一个反斜杠:

bind '"3\xE2\x88\xAB"':'"\"'

回答by Chris Page

You could customize the keyboard map to use a different key for entering backslash. Look in

您可以自定义键盘映射以使用不同的键来输入反斜杠。在看

Preferences > Settings > [profile] > Keyboard

首选项 > 设置 > [配置文件] > 键盘

For example, you could map Control-F1 to backslash.

例如,您可以将 Control-F1 映射到反斜杠。

Note that the default keyboard map maps Option-Left/Right Arrow to M-b/f, so you could use those instead of using Option for Meta (you'd have to get used to using the arrow keys instead of b and f, but I've never been able to get used to using b and f and prefer the arrow keys).

请注意,默认键盘映射将 Option-Left/Right Arrow 映射到 Mb/f,因此您可以使用它们而不是使用 Option for Meta(您必须习惯使用箭头键而不是 b 和 f,但我'从未习惯使用 b 和 f 并且更喜欢箭头键)。

回答by chepner

The escape key works as a meta key by default; no need to use option as the meta key (other than its more convenient location).

转义键默认用作元键;不需要使用选项作为元键(除了它更方便的位置)。

回答by perbu

I had the same issue. This is how I solved it.

我遇到过同样的问题。我就是这样解决的。

I replaced the built in terminal with iTerm2, which also gave me a few other nice features. To get a sane Meta-key i did the following:

我用 iTerm2 替换了内置终端,这也给了我一些其他不错的功能。为了获得一个健全的元密钥,我做了以下事情:

For the profile I wanted to use I checked "Alt sends +Esc", which gave me back a sane Meta-key that works in Emacs, Bash and others. However, I did lose the backslash key. So, to get it back and added a binding in the profile that does "Send text: \" and then I bound it to my backspace key combo (Shift-Alt-7, I'm Norwegian).

对于我想使用的配置文件,我选中了“Alt 发送 +Esc”,这给了我一个可以在 Emacs、Bash 和其他人中使用的健全的元键。但是,我确实丢失了反斜杠键。因此,为了取回它并在配置文件中添加了一个“发送文本:\”的绑定,然后我将它绑定到我的退格键组合(Shift-Alt-7,我是挪威人)。

Now I have M-f, M-b in Emacs, M-. in Bash and I'm able to send backslashes. I also have a "Visor shell session" that I can have slide down by pressing another key combination.

现在我在 Emacs 中有 Mf,Mb,M-。在 Bash 中,我可以发送反斜杠。我还有一个“Visor shell 会话”,我可以通过按另一个组合键将其滑下来。

回答by habibalamin

This is years late, but for people coming across this page whilst searching for a solution, as I did, I have decided to build one myself.

这已经晚了好几年了,但是对于在寻找解决方案时遇到此页面的人,就像我一样,我决定自己构建一个。

It is a simple status bar app that runs in the background and rewrites all left-Alt + $KEY key events to two key events in rapid succession, Esc, then $KEY; however, it only does this if Terminal.app is the focused application.

它是一个简单的状态栏应用程序,在后台运行并将所有 left-Alt + $KEY 键事件重写为快速连续的两个键事件,Esc,然后是 $KEY;但是,只有当 Terminal.app 是焦点应用程序时,它才会这样做。

You can find it here at https://github.com/habibalamin/Metalt.

您可以在https://github.com/habibalamin/Metalt 上找到它。