Mac 里我最喜欢的功能 - Emacs 快捷键 - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
yangg
0.14D
V2EX    Apple

Mac 里我最喜欢的功能 - Emacs 快捷键

  •  
  •   yangg 2019-08-06 22:02:14 +08:00 3305 次点击
    这是一个创建于 2258 天前的主题,其中的信息可能已经有所发展或是发生改变。

    刚接触 Mac 时,最喜欢的就是 Mac 所有输入框都有类似 Emacs 的快捷键(因为有过 vim 和 Emacs 经验),日常也经常使用这些快捷键。 一直不知道原来这些快捷键还可以自定义,今天因为 iTerm2 里无法使用 Option + . 快捷键的问题,搜索到一个回答提到了怎么自定义这些快捷键。

    Customize the behavior of Cocoa ’ s text system

    苹果关于 Cocoa 的文档

    下面是我的配置(在 MWeb 和 TextMate 里测试通过):

    • 更多 emacs 里移动和删除单词的
    • 选中单词的
    • Vscode 里很喜欢的上下移动行及往上下复制行的快捷键(使用了 vim 里的上下 j, k )
    // 在 ~/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

    iTerm2 里无法使用 Option + . 问题

    Preferences - Profiles - Keys 将下面的 Left Key 改为 Esc+ 就可以了

    参考

    Cocoa 常用命令

    原文地址: https://uedsky.com/2019-08/mac-custom-cocoa-text-system/

    5 条回复    2019-08-07 09:05:24 +08:00
    yangg
        1
    yangg  
    OP
       2019-08-06 22:04:16 +08:00
    tsohgdivil
        2
    tsohgdivil  
       2019-08-06 22:31:13 +08:00
    我一直都是用 Karabiner-Elements 的,没想到还能这样,谢谢分享
    lululau
        3
    lululau  
       2019-08-06 22:52:27 +08:00 via iPhone
    这个文件用 JSON 格式,你试试点击任意应用程序的 Help 菜单,程序会不会崩溃,之前遇到过这个问题,改回 binary 格式就好了
    lululau
        4
    lululau  
       2019-08-06 22:55:52 +08:00
    JSON 格式 => 文本格式
    yangg
        5
    yangg  
    OP
       2019-08-07 09:05:24 +08:00
    @lululau 文本没问题哦,
    原文说
    Specified in an dictionary file that must have an extension of .dict; the format of this file should be an XML property list, but the text system can also understand old-style (NeXT era) property lists.

    To customize bindings, you create a file named DefaultKeyBinding.dict in ~/Library/KeyBindings/ and specify bindings to augment or replace the standard bindings. You may use the standard bindings file as a template. It is recommended that you use the Property List Editor application to edit a bindings dictionary. You may use another application such as TextEdit or Xcode, but if you do you must ensure the encoding of the saved file is UTF8.

    就是一个字典文件,用 utf8 就行了,我直接用 textmate 编辑的
    关于     帮助文档     自助推广系统     博客     API     FAQ     Solana     2718 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 27ms UTC 07:41 PVG 15:41 LAX 00:41 JFK 03:41
    Do have faith in what you're doing.
    ubao snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86