-
获取权限,终端分别敲入以下2个指令
sudo chmod 666 /Applications/Xcode.app/Contents/Frameworks/IDEKit.framework/Resources/IDETextKeyBindingSet.plistsudo chmod 777 /Applications/Xcode.app/Contents/Frameworks/IDEKit.framework/Resources/
-
找到Xcode中的自带的配置文件
/Applications/Xcode.app/Contents/Frameworks/IDEKit.framework/Versions/A/Resources/IDETextKeyBindingSet.plist
这个文件里配置了一些可以设置快捷键的操作, 使用常用的编辑器打开它。
-
然后看看下面这段配置, (来自gist,感谢作者@gdavis )
<key>GDI Commands</key> <dict> <key>GDI Duplicate Current Line</key> <string>selectLine:, copy:, moveToEndOfLine:, insertNewline:, paste:, deleteBackward:</string> <key>GDI Delete Current Line</key> <string>moveToEndOfLine:, deleteToBeginningOfLine:, deleteBackward:, moveDown:, moveToEndOfLine:</string> <key>GDI Move Current Line Up</key> <string>selectLine:, cut:, moveUp:, moveToBeginningOfLine:, insertNewLine:, paste:, moveBackward:</string> <key>GDI Move Current Line Down</key> <string>selectLine:, cut:, moveDown:, moveToBeginningOfLine:, insertNewLine:, paste:, moveBackward:</string> <key>GDI Insert Line Above</key> <string>moveUp:, moveToEndOfLine:, insertNewline:</string> <key>GDI Insert Line Below</key> <string>moveToEndOfLine:, insertNewline:</string> </dict>
这个dict是一组可以设置快捷键的操作,里面的key是名称,对应的string是对应的一组操作,从名字本身也可以看出是什么意思,而且也可以根据这些自由装配成自己的别的快捷操作。
- GDI Duplicate Current Line 复制当前行到下面一行
- GDI Delete Current Line 删除当前行
- GDI Move Current Line Up 把当前行往上移动一行
- GDI Move Current Line Down 把当前行往下移动一行
- GDI Insert Line Above 在当前行上面增加一空行
- GDI Insert Line Below 在当前行下面增加一空行(不管光标是否在行尾)
把这段配置放到上面提到的
IDETextKeyBindingSet.plist
里,放在文件的最后的这两行之前:</dict> </plist>
4.增加自定义快捷键配置
1、command+, 调出xcode preferences.
2、选择 Key Bindings 标签,在右上方搜索
GDI
, 会出现类似下图的显示,如果没有的话,请检查上面的每步操作。
参考文章:
http://hi.baidu.com/castiello_ybx/item/20e9945932516ac89e2667ea
http://joeyio.com/2013/07/22/xcode_key_binding_like_eclipse/
http://www.cnblogs.com/hl13571/archive/2010/12/17/1909096.html