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.
@TypeOneError - how do you find the available keys which work? If I try the exact same .dict file as you gave, except I use an ^$L instead of ^$K, then these key combinations don't get picked up by XCode. I don't get it, since ^$L is not already in use.
What do you mean by "after some experimentation"? Does this mean that getting this to work is a bit of a trial-and-error?
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.