Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode: Delete line hot-key

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?

like image 719
typeoneerror Avatar asked Jan 25 '09 00:01

typeoneerror


People also ask

What is the shortcut to delete a line?

On your keyboard, press and hold the left or right Shift key and then press the End key to highlight the entire line. Press the Delete key to delete the line of text.

How do I select a line in Xcode?

Shift + Control + Click First, hold Shift and Control (^) and then click where you want to select multiple lines and then start typing. One small caveat: unlike other text editors where you can click that same line to unselect the multi-line selection, Xcode doesn't support that yet.

How do you shift to the end of a line?

Moving the CursorEnd – Move cursor to end of current line. Ctrl+Home – Move cursor to top of the text entry field. Ctrl+End – Move cursor to bottom of the text entry field.


2 Answers

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.

like image 185
typeoneerror Avatar answered Sep 18 '22 12:09

typeoneerror


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.

like image 37
Ashley Clark Avatar answered Sep 18 '22 12:09

Ashley Clark