macos Mac OS X Leopard 上的 Emacs 键绑定

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

Emacs on Mac OS X Leopard key bindings

macosemacskeyboard-shortcutskey-bindings

提问by Kyle Cronin

I'm a Mac user and I've decided to learn Emacs. I've readthat to reduce hand strain and improve accuracy the CTRLand CAPS LOCKkeys should be swapped. How do I do this in Leopard?

我是 Mac 用户,我决定学习 Emacs。我已经读过,为了减少手部疲劳并提高准确性CTRLCAPS LOCK应该交换和键。我如何在 Leopard 中做到这一点?

Also, in Terminal I have to use the ESCkey to invoke meta. Is there any way to get the alt/option key to invoke meta instead?

此外,在终端中,我必须使用ESC密钥来调用元。有没有办法让 alt/option 键来调用元?

update:While the control key is much easier to hit now, the meta key is also used often enough that its position on my MacBook and Apple Keyboard also deserves attention. In fact, I find that the control key is actually easier to hit, so I've remapped my control key to act as a meta key. Does anyone have a better/more standard solution?

更新:虽然控制键现在更容易点击,但元键也经常使用,以至于它在我的 MacBook 和 Apple 键盘上的位置也值得关注。事实上,我发现控制键实际上更容易点击,所以我重新映射了我的控制键以充当元键。有没有人有更好/更标准的解决方案?

回答by Kyle Cronin

Swapping CTRL and CAPS LOCK

交换 CTRL 和 CAPS LOCK

  1. Go into System Preferences
  2. Enter the Keyboard & Mousepreference pane
  3. In the Keyboardtab, click Modifier Keys...
  4. Swap the actions for Caps Lockand Control.
  1. 进入系统偏好设置
  2. 进入键盘和鼠标首选项面板
  3. 键盘选项卡中,单击修饰键...
  4. 交换Caps LockControl 的操作

alt text

替代文字

Using ALT/OPTION as META

使用 ALT/OPTION 作为 META

  1. In the menu bar, click Terminal
  2. Click Preferences...
  3. Under the Settingstab, go to the Keyboardtab
  4. Check the box labeled Use option as meta key
  1. 在菜单栏中,单击终端
  2. 单击首选项...
  3. 设置选项卡下,转到键盘选项卡
  4. 选中标记为使用选项作为元键的框

alt text

替代文字

That's it! You should be well on your way to becoming an Emacs master!

而已!您应该顺利成为 Emacs 大师!

回答by Chris

For reference, here are the key bindings, for moving around text:

作为参考,以下是用于移动文本的键绑定:

?+ - move left one word
?+ - move right one word
?+ delete- back delete one word
Shift+ ?+ delete- foward delete one word
?+ - move up one paragraph
?+ - move down one paragraph
?+ - move to start of current line
?+ - move to end of current line
Shift+ any of the above extend selection by appropriate amount

?+ - 左移一个单词
?+ - 右移一个单词
?+ delete- 向后删除一个单词
Shift+ ?+ - 向前delete删除一个单词
?+ - 上移一段
?+ - 下移一段
?+ - 移到当前行的开头
?+ - 移到结尾当前行的
Shift+ 任何上述扩展选择适当的数量

Click then drag - select text
Double-click then drag - select text, wrapping to word ends
Triple-click then drag - select text, wrapping to paragraph ends

单击然后拖动 - 选择文本
双击然后拖动 - 选择文本,环绕到词尾
三击然后拖动 - 选择文本,环绕到段落结尾

Shift+ Select text with mouse - add to selection (contiguous)
?+ Select text with mouse - add to selection (non-contiguous)
?+ Drag - select rectangular area (non-contiguous)
?+ ?+ drag - add rectangular area to selection
Drag selection - move text
?+ drag selection - copy text

Shift+ 用鼠标选择文本 - 添加到选择(连续)
?+ 用鼠标选择文本 - 添加到选择(非连续)
?+ 拖动 - 选择矩形区域(非连续)
?+ ?+ 拖动 - 添加矩形区域到选择
拖动选择 - 移动文本
?+ 拖动选择 - 复制文本

Ctrl+ A- move to start of current paragraph
Ctrl+ B- move left one character
Ctrl+ D- forwards delete
Ctrl+ E- move to end of current paragraph
Ctrl+ F- move right one character
Ctrl+ H- delete
Ctrl+ K- delete remainder of current paragraph
Ctrl+ L- center the window on the current line
Ctrl+ N- move down one line
Ctrl+ O- insert new line after cursor
Ctrl+ P- move up one line
Ctrl+ T- transpose (swap) two surrounding character
Ctrl+ V- move to end, then left one character
Ctrl+ Y- paste text previously deleted with Ctrl- K

Ctrl+ A- 移动到当前段落的开头
Ctrl+ B- 向左移动一个字符
Ctrl+ D- 向前删除
Ctrl+ E- 移动到当前段落的末尾
Ctrl+ F- 向右移动一个字符
Ctrl+ H- 删除
Ctrl+ K- 删除当前段落的剩余部分
Ctrl+ L- 将窗口居中line
Ctrl+ N- 下移一行
Ctrl+ O- 在光标后插入新行
Ctrl+ P- 上移一行
Ctrl+ T- 转置(交换)两个周围的字符
Ctrl+ V- 移到末尾,然后左移一个字符
Ctrl+ Y- 粘贴先前删除的文本Ctrl—— K

Add Optionto Ctrl+ For Ctrl+ Bto move a word instead of a character at a time.

添加OptionCtrl+FCtrl+B以一次移动一个单词而不是一个字符。

回答by R.Klug

I really like the answer provided by Kyle Cronin, but I want to add one thing - make sure you select the appropriate keyboard for this to work. If you have an external keyboard plugged into your laptop, then there are is an additional drop down box and you will need to do this for both keyboards (or at least for your external keyboard). The screen shot below shows the "Select Keyboard" dialog box - I have selected "Joint Mac Keyboard", which is MacBook's way of saying GoldTouch external keyboard - the default is the built-in keyboard.
Screen shot showing "Select Keyboard" dialog

我真的很喜欢 Kyle Cronin 提供的答案,但我想添加一件事 - 确保您选择合适的键盘使其工作。如果您的笔记本电脑中插入了外部键盘,那么还有一个额外的下拉框,您需要为两个键盘(或至少为您的外部键盘)执行此操作。下面的屏幕截图显示了“选择键盘”对话框——我选择了“Joint Mac 键盘”,这是 MacBook 的 GoldTouch 外接键盘的说法——默认是内置键盘。
显示“选择键盘”对话框的屏幕截图

Once I figured that out - this works great for me!

一旦我想通了 - 这对我来说非常有用!

回答by mike511

The other answer was very complete, but additionally I'd mention I just set the caps lock key to a second control key instead of swapping them.

另一个答案非常完整,但另外我要提到的是,我只是将大写锁定键设置为第二个控制键,而不是交换它们。

Also, you'll notice that the large majority of the text entry fields in Mac OS X already accept emacs keystrokes (^A beginning of line, ^E end of line, ^P, ^N, ^K, ^Y, etc)

此外,您会注意到 Mac OS X 中的大多数文本输入字段已经接受 emacs 击键(^A 行首、^E 行尾、^P、^N、^K、^Y 等)

good luck

祝你好运

回答by mike511

If you use emacs over an ssh connection, or through a machine not on your local computer, the page up/page down buttons scroll through the terminal buffer - in my experience, not too helpful.

如果您通过 ssh 连接或通过不在本地计算机上的机器使用 emacs,则向上翻页/向下翻页按钮会在终端缓冲区中滚动 - 根据我的经验,这不是很有帮助。

You can set your page down and page up buttons to send the appropriate commands to emacs. In emacs, you can scroll through the emacs buffer like so:

您可以设置向下翻页和向上翻页按钮以向 emacs 发送适当的命令。在 emacs 中,您可以像这样滚动 emacs 缓冲区:

  • Page Up: Ctl-v
  • Page Down: Esc-v
  • 向上翻页:Ctl-v
  • 向下翻页:Esc-v

So, to have the terminal send these commands to emacs, follow the instructions above to alter the Alt keys for Meta. However, instead of setting the "use option as meta" option, find the "page down" and "page up" options.

因此,要让终端将这些命令发送到 emacs,请按照上述说明更改 Meta 的 Alt 键。但是,不要设置“use option as meta”选项,而是找到“page down”和“page up”选项。

Page Down

向下翻页

Double click the "page down" option to edit it. Change Actionto "send string to shell"and enter \026as the string. Save it.

双击“向下翻页”选项进行编辑。将Action更改为“send string to shell”并输入\026作为字符串。保存。

Page Up

向上翻页

Double click the "page up" button to edit it. Change Actionto "send string to shell"and enter \033vas the string. Save it.

双击“向上翻页”按钮进行编辑。将Action更改为“send string to shell”并输入\033v作为字符串。保存。

回答by dnolen

Not sure if you're totally married to using Emacs from the terminal, but another option is to use Carbon Emacs (my favorite) and Aquamacs (very Mac-like). Carbon Emacs uses the command key for meta, this is nice because you can do Control-Meta commands just by holding Control and Command down instead of first hitting escape then the control key sequence.

不确定您是否完全同意从终端使用 Emacs,但另一种选择是使用 Carbon Emacs(我最喜欢的)和 Aquamacs(非常像 Mac)。Carbon Emacs 使用命令键作为元,这很好,因为你可以通过按住 Control 和 Command 来执行 Control-Meta 命令,而不是先按 Esc 然后按控制键序列。

Also, if you're a serious Emacs user I thoroughly recommend that you get a keyboard suited for programming (that is one that is completely reprogrammable by itself). I use a Kinesis, it's a little bit of money but they are extremely durable and quite nice.

此外,如果您是一个认真的 Emacs 用户,我强烈建议您使用适合编程的键盘(即完全可以自行重新编程的键盘)。我使用 Kinesis,它有点钱,但它们非常耐用且非常好。

回答by Alexandre Paes

Personally i have setup caps lock to behave like command on the system preferences and then on my emacs init.el file have:

就我个人而言,我在系统首选项上设置了大写锁定,其行为类似于命令,然后在我的 emacs init.el 文件中具有:

(setq mac-command-modifier 'ctrl)

(setq mac-command-modifier 'ctrl)

and this lets me use caps lock as command in most osx applications and as control in emacs. works well enough for me.

这让我可以在大多数 osx 应用程序中使用大写锁定作为命令,并在 emacs 中作为控件使用。对我来说效果很好。

回答by Charles Merriam

Your joy is just beginning. Other tricks include:

你的快乐才刚刚开始。其他技巧包括:

  • Use the left and right shift keys to also be ( and ) for fast typing.
  • Remap your fn key or another key to be "super".
  • Make caps lock be control, but only with another key. By itself, it is escape.
  • 使用左右 shift 键也可以 ( 和 ) 进行快速打字。
  • 将您的 fn 键或另一个键重新映射为“超级”。
  • 使大写锁定成为控制,但只能用另一个键。就其本身而言,它就是逃避。

Read the excellent article at http://stevelosh.com/blog/2012/10/a-modern-space-cadet/for a lot more information.

阅读http://stevelosh.com/blog/2012/10/a-modern-space-cadet/ 上的优秀文章,了解更多信息。

回答by lawlist

This thread was started 5 years ago and there is no mention of ns-win.elor build --with-ns. Here are all the key bindings available (out of the box) in Emacs Trunk as of October 2013. And, of course, you can create your own. Personally, I have one init.elwith all my key bindings that can be used with Windows XP through Parallels on OSX, and also with OSX natively. Since the user can define his / her own keyboard shortcuts, I do not see a need to remap the keyboard in system preferences (with an Apple U.S. keyboard) unlessusing a keyboard that does not include the Command key. But, would I throw away my stash of IBM clicky keyboards with trackpoint built in? Of course not. :) I'm taking my IBM clicky keyboards with me into the next life. Any hand strain is most likely caused by improper wrist / arm / elbow position, not by hitting control versus caps lock. Accuracy is improved through practice, and with the help of a boss looking over your shoulder to see how you are coming along -- i.e., a little pressure to be more productive :)

这个线程是在 5 年前开始的,没有提到ns-win.el或 build --with-ns。以下是截至 2013 年 10 月 Emacs Trunk 中所有可用(开箱即用)的键绑定。当然,您也可以创建自己的键绑定。就我个人而言,我拥有一个init.el可以通过 OSX 上的 Parallels 与 Windows XP 以及本机 OSX 一起使用的所有键绑定。由于用户可以定义他/她自己的键盘快捷键,我认为不需要在系统首选项(使用 Apple US 键盘)中重新映射键盘,除非使用不包含 Command 键的键盘。但是,我会扔掉我的内置跟踪点的 IBM Clicky 键盘吗?当然不是。:) 我要带着我的 IBM Clicky 键盘进入下辈子。任何手部劳损很可能是由不当的手腕/手臂/肘部位置引起的,而不是由击中控制与大写锁定引起的。通过练习提高准确性,并在老板的帮助下看着你的肩膀,看看你的进展情况——也就是说,有点压力要提高工作效率:)

(define-key global-map [?\s-,] 'customize)
(define-key global-map [?\s-'] 'next-multiframe-window)
(define-key global-map [?\s-`] 'other-frame)
(define-key global-map [?\s-~] 'ns-prev-frame)
(define-key global-map [?\s--] 'center-line)
(define-key global-map [?\s-:] 'ispell)
(define-key global-map [?\s-?] 'info)
(define-key global-map [?\s-^] 'kill-some-buffers)
(define-key global-map [?\s-&] 'kill-this-buffer)
(define-key global-map [?\s-C] 'ns-popup-color-panel)
(define-key global-map [?\s-D] 'dired)
(define-key global-map [?\s-E] 'edit-abbrevs)
(define-key global-map [?\s-L] 'shell-command)
(define-key global-map [?\s-M] 'manual-entry)
(define-key global-map [?\s-S] 'ns-write-file-using-panel)
(define-key global-map [?\s-a] 'mark-whole-buffer)
(define-key global-map [?\s-c] 'ns-copy-including-secondary)
(define-key global-map [?\s-d] 'isearch-repeat-backward)
(define-key global-map [?\s-e] 'isearch-yank-kill)
(define-key global-map [?\s-f] 'isearch-forward)
(define-key global-map [?\s-g] 'isearch-repeat-forward)
(define-key global-map [?\s-h] 'ns-do-hide-emacs)
(define-key global-map [?\s-H] 'ns-do-hide-others)
(define-key global-map [?\s-j] 'exchange-point-and-mark)
(define-key global-map [?\s-k] 'kill-this-buffer)
(define-key global-map [?\s-l] 'goto-line)
(define-key global-map [?\s-m] 'iconify-frame)
(define-key global-map [?\s-n] 'make-frame)
(define-key global-map [?\s-o] 'ns-open-file-using-panel)
(define-key global-map [?\s-p] 'ns-print-buffer)
(define-key global-map [?\s-q] 'save-buffers-kill-emacs)
(define-key global-map [?\s-s] 'save-buffer)
(define-key global-map [?\s-t] 'ns-popup-font-panel)
(define-key global-map [?\s-u] 'revert-buffer)
(define-key global-map [?\s-v] 'yank)
(define-key global-map [?\s-w] 'delete-frame)
(define-key global-map [?\s-x] 'kill-region)
(define-key global-map [?\s-y] 'ns-paste-secondary)
(define-key global-map [?\s-z] 'undo)
(define-key global-map [?\s-|] 'shell-command-on-region)
(define-key global-map [s-kp-bar] 'shell-command-on-region)
;; (as in Terminal.app)
(define-key global-map [s-right] 'ns-next-frame)
(define-key global-map [s-left] 'ns-prev-frame)

(define-key global-map [home] 'beginning-of-buffer)
(define-key global-map [end] 'end-of-buffer)
(define-key global-map [kp-home] 'beginning-of-buffer)
(define-key global-map [kp-end] 'end-of-buffer)
(define-key global-map [kp-prior] 'scroll-down-command)
(define-key global-map [kp-next] 'scroll-up-command)

;; Allow shift-clicks to work similarly to under Nextstep.
(define-key global-map [S-mouse-1] 'mouse-save-then-kill)
(global-unset-key [S-down-mouse-1])

回答by Gene T

(not an ergonomic keyboard, but i really like the keys' travel and feel, and Control key , Caps Lock are swapped).

(不是符合人体工程学的键盘,但我真的很喜欢按键的行程和感觉,并且 Control 键和 Caps Lock 被交换了)。

http://matias.ca/osxkeyboard/index.php

http://matias.ca/osxkeyboard/index.php