刚接触 Mac 时,最喜欢的就是 Mac 所有输入框都有类似 Emacs 的快捷键(因为有过 vim 和 Emacs 经验),日常也经常使用这些快捷键。
一直不知道原来这些快捷键还可以自定义,今天因为 iTerm2 里无法使用 Option + .
快捷键的问题,搜索到一个回答提到了怎么自定义这些快捷键。
苹果关于 Cocoa 的文档
下面是我的配置(在 MWeb 和 TextMate 里测试通过):
// 在 ~/Library/KeyBindings/ 目录下添加 DefaultKeyBinding.dict 文件,这个目录默认不存在,先创建
// targetDir=~/Library/KeyBindings; [ -d $targetDir ] || mkdir $targetDir; ln -sf ~/Dropbox/conf/DefaultKeyBinding.dict $targetDir
// 此文件更改后,完全退出某个 app,重新打开即可使用
{
/* Additional Emacs bindings */
"~f" = "moveWordForward:";
"~b" = "moveWordBackward:";
"~d" = "deleteWordForward:";
"~h" = "deleteWordBackward:";
"~<" = "moveToBeginningOfDocument:";
"~>" = "moveToEndOfDocument:";
"~v" = "pageUp:"; /* ^v pageDown */
// selections
"~F" = "moveWordForwardAndModifySelection:";
"~B" = "moveWordBackwardAndModifySelection:";
"^," = "moveToBeginningOfDocumentAndModifySelection:"; /* select to beginning */
"^." = "moveToEndOfDocumentAndModifySelection:"; /* select to ending */
"~l" = "selectLine:";
// compounds
// "~t" = "moveToBeginningOfLine:"; // this two line is for debugging
// "~y" = "deleteToEndOfLine:";
"^K" = ("moveToBeginningOfLine:", "deleteToEndOfLine:", "deleteForward:");
"~j" = ("moveToBeginningOfLine:", "deleteToEndOfLine:", "deleteForward:", "moveDown:", "yank:", "insertNewlineIgnoringFieldEditor:", "moveBackward:");
"~k" = ("moveToBeginningOfLine:", "deleteToEndOfLine:", "deleteBackward:", "moveUp:", "moveToEndOfLine:", "insertNewlineIgnoringFieldEditor:", "yank:");
"~J" = ("moveToBeginningOfLine:", "deleteToEndOfLine:", "yank:", "insertNewlineIgnoringFieldEditor:", "yank:");
"~K" = ("moveToBeginningOfLine:", "deleteToEndOfLine:", "yank:", "insertNewlineIgnoringFieldEditor:", "yank:", "moveUp:");
// "~K" = ("moveToBeginningOfLine:", "deleteToEndOfLine:", "yank:", "moveToBeginningOfLine:", "yank:", "insertNewlineIgnoringFieldEditor:", "moveBackward:");
}
Cocoa 默认快捷键定义在(可以看看哪些不知道的):
/System/Library/Frameworks/AppKit.framework/Resources/StandardKeyBinding.dict
Option + .
问题Preferences - Profiles - Keys
将下面的 Left ⌥ Key
改为 Esc+
就可以了
Cocoa 常用命令
原文地址: https://uedsky.com/2019-08/mac-custom-cocoa-text-system/
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.