I'm looking for a way to map some hot-keys to "delete the line that my cursor is on" in Xcode. I found "delete to end of line" and "delete to beginning of line" in the text key bindings, but I am missing how to completely delete the line no matter what I have selected. TextMate has this functionality mapped to Ctrl+Shift+D and I'd like the same thing if possible. Any ideas?
You can set up a system-wide key binding file that will apply to all Cocoa apps.
To do what you want it should like like this:
In your home folder, Library/KeyBindings/DefaultKeyBinding.dict
{
"^D" = (
"moveToBeginningOfLine:",
"deleteToEndOfLine:",
);
}
I believe if you only want it to apply to Xcode you can name the file PBKeyBinding.dict
instead but I didn't try that myself. You can read more about this system here and here.
Thanks for the help, Ashley. After some experimentation I mapped my favorite TextMate commands (duplicate line, delete line). I created the file ~/Library/KeyBindings/PBKeyBinding.dict and added the following:
{
"^$K" = (
"selectLine:",
"cut:"
);
"^$D" = (
"selectLine:",
"copy:",
"moveToEndOfLine:",
"insertNewline:",
"paste:"
);
}
The added "deleteBackward:" backs up one line after removing the line's content. You could probably just use "selectLine:" as well.
You can set up a system-wide key binding file that will apply to all Cocoa apps.
To do what you want it should like like this:
In your home folder, Library/KeyBindings/DefaultKeyBinding.dict
{
"^D" = (
"moveToBeginningOfLine:",
"deleteToEndOfLine:",
);
}
I believe if you only want it to apply to Xcode you can name the file PBKeyBinding.dict
instead but I didn't try that myself. You can read more about this system here and here.
As I don't always work on the same xcode I prefer not to install scripts.
Xcode uses some sub-set of emacs commands. I use this approach to quickly delete a line. ^k (control-k) deletes from the cursor to the end of the line. Doing it twice also deletes the carriage return and takes up the next line. ^a takes you to the start of the line.
So to delete a complete line from the beginning you can use ^a^k^k.
I was looking for a solution to this, and I tried Ashley Clark's, but it turns out there's an easier option using an included User Script called delete Line.
- Open the weird menu to the left of 'help' that looks like a scroll.
- Choose Edit User Scripts...
- Click the Key Bindings tab
- Expand the Text section
- Double click the ⌘ column next to 'Delete Line' and type your hotkey. It may warn you that you stole it from some other command but that's fine.
Done! You can do the same for Move Line Up and Move Line Down if you're an Eclipse junkie like me.
<key>Custom Keyword Set</key>
<dict>
<key>Delete Current Line In One Hit</key>
<string>moveToEndOfLine:, deleteToBeginningOfLine:, deleteToEndOfParagraph:</string>
</dict>
I suggest to create your customized dictonary in your file IDETextKeyBindingSet.plist.
So:
- close Xcode;
- open Terminal;
- sudo nano /Applications/Xcode.app/Contents/Frameworks/IDEKit.framework/Resources/IDETextKeyBindingSet.plist
- add new custom section, for instance code in top;
- save, exit and open Xcode;
- [Xcode > Preferences > Key Binding]
- search “Delete..” and create the new shortcut.
moveToBeginningOfLine:, deleteToEndOfLine:, deleteBackward:
. –
Seventeenth For Xcode 9.0(beta), inserting customized key dictionary into IDETextKeyBindingSet.plist working fine for me.You need to restart XCode if already open and after next launch you will find new customized shortcuts under the KeyBindings menu.
<key>Customized</key>
<dict>
<key>Delete Rest Of Line</key>
<string>deleteToEndOfLine:</string>
<key>Delete Line</key>
<string>moveToBeginningOfLine:, deleteToEndOfLine:</string>
<key>Duplicate Current Line</key>
<string>selectLine:, copy:, moveToEndOfLine:, insertNewline:, moveToBeginningOfLine:, paste:</string>
</dict>
This works for me (Xcode 4.4.1):
Same steps like described here: Xcode duplicate line (Halley's answer)
But instead of:
selectLine:, copy:, moveToEndOfLine:, insertNewline:, paste:, deleteBackward:
Use:
selectLine:, moveToBeginningOfLine:, deleteToEndOfLine:
If you're having trouble in modern Xcode (which I was) solution for this in Xcode 7.2 is to do what Opena mentioned here with screenshots or in text form via Velthune's answer. Since I wanted a more direct command I simplified the command to:
selectLine:, delete:, moveToBeginningOfLine:
Of course in the Xcode's Preferences >> Key Bindings, you can just find the command double-click under the Key column and give it your own binding of Ctrl+Shift+D.
© 2022 - 2024 — McMap. All rights reserved.