×

Xcode 增加复制一行、删除一行的快捷键

Falcon 2020-02-11 views:
自动摘要

正在生成中……

 
167
 
+50
  1. Go to this folder which contains dark side of the force:

    • Xcode 4.2 or prior: /Developer/Library/PrivateFrameworks/IDEKit.framework/Resources
    • Xcode 4.3 or later: /Applications/Xcode.app/Contents/Frameworks/IDEKit.framework/Resources.
  2. Open IDETextKeyBindingSet.plist.

  3. Add a new dictionary and a new command item as the screenshot below (name them what you want): Editing the plist

    That's: selectLine:, copy:, moveToEndOfLine:, insertNewline:, paste:, deleteBackward:

  4. Restart Xcode and go to Preferences - Key Bindings, search for your command.

  5. Set a key combination for the command: Key Bindings

  6. Finally unleashed the power of key bindings on Xcode... Enjoy it!

  • 3
    @MichalStefanow, the location that you wrote is actually the same location that /Applications/Xcode.app/Contents/Frameworks/IDEKit.framework/Resources alias points to. Otherwise, I've successfully followed Halley's steps on version 4.3.2 ... I suggest you backup up the original file and then open it in Xcode itself (and not in TextEdit). Also, regarding the permissions: changing them (only for the file itself; no recursion needed) in Finder worked just fine. – Blaz Apr 29 '12 at 11:13 
  • 28
    Big thanx! For lazy users - selectLine:, copy:, moveToEndOfLine:, insertNewline:, paste:, deleteBackward: – Vlad Tsepelev Jun 8 '12 at 11:59 
  • 15
    If your xCode crashes! Close xCode, open file with any text editor and add your dictionary: <key>Custom</key> <dict> <key>Duplicate Current Line</key> <string>selectLine:, copy:, moveToEndOfLine:, insertNewline:, paste:, deleteBackward:</string> </dict> – Vlad Tsepelev Jun 8 '12 at 12:04
  • 2
    Works for me in XCode 4.4.1! Had some trouble changing permissions (finder or chmod 777 and start with sudo from terminal didn't work, for some reason). I copied the file to somewhere else, edited it, and overwrote the original one, that worked. – Ixx Sep 1 '12 at 15:33
  • 2
    I am android dev and when I started to trying ios dev I realized how android studio (or intellij idea) is good. – IlyaEremin Jul 5 '16 at 18:16
76

Update 2020

Works on Xcode versions: 11.3.1 too

Works in Xcode versions: 7.1, 7.3, 7.3.1, 8.0, 8.1, 8.2, 8.3, 9.0, 9.1, 9.2, 10.0, 10.1, 10.2.1

Instruction

  1. Give permissions to edit the following files. Most of the time OS will not allow you to edit the files.

for 11.3.1 version

sudo chmod 666 /Applications/Xcode.app/Contents/Frameworks/IDEKit.framework/Versions/A/Resources//IDETextKeyBindingSet.plist

sudo chmod 777 /Applications/Xcode.app/Contents/Frameworks/IDEKit.framework/Versions/A/Resources/

below 11.3 versions


sudo chmod 666 /Applications/Xcode.app/Contents/Frameworks/IDEKit.framework/Resources/IDETextKeyBindingSet.plist

sudo chmod 777 /Applications/Xcode.app/Contents/Frameworks/IDEKit.framework/Resources/
  1. Edit the the file, by writing the following command: (Open it in sublime or text editor if you can)

for 11.3.1

open  

/Applications/Xcode.app/Contents/Frameworks/IDEKit.framework/Versions/A/Resources/

for below versions

open /Applications/Xcode.app/Contents/Frameworks/IDEKit.framework/Versions/A/Resources/IDETextKeyBindingSet.plist
  1. Append the following xml snippets:
<key>custom</key>
<dict>
    <key>Duplicate Current Line</key>
    <string>moveToBeginningOfLine:, deleteToEndOfLine:, yank:, insertNewline:, moveToBeginningOfLine:, yank:</string>
    <key>Duplicate Lines</key>
    <string>selectLine:, copy:, moveToEndOfLine:, insertNewline:, paste:, deleteBackward:</string>
    <key>Delete Line</key>
    <string>selectLine:, deleteBackward:</string>
</dict>

Screenshots

enter image description here

and Restart Xcode and go to Preferences - Key Bindings, search for the command we typed (Duplicate Lines&Duplicate Current Line).

enter image description here

Thats it.