Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I create a Delete-Line Keyboard shortcut in Xcode 8? The Xcode 3 solutions do not work anymore

In previous versions of Xcode it was possible to create a key binding to delete the current line. There were different solutions and they are described for example here:

Xcode: Delete line hot-key

Xcode duplicate/delete line

http://bigdiver.wordpress.com/2009/09/11/configure-homeend-key-bidings-on-mac-os-x/

http://www.betadesigns.co.uk/Blog/2010/02/03/custom-xcode-shortcuts/

All solutions include modifying one of these files:

~/Library/Application Support/Xcode/Key Bindings/*.pbxkeys
~/Library/KeyBindings/DefaultKeyBinding.dict
~/Library/KeyBindings/PBKeyBinding.dict

A good resource for the existing shortcuts in Xcode 4 is http://cocoasamurai.blogspot.com/2011/03/xcode-4-keyboard-shortcuts-now.html . There are many listed regarding deletion, but none for "delete line".

BUT, these solutions do NOT work since Xcode 4.

Update: Issue is still the same as of Xcode 5.1.1

Update: Issue is still the same as of Xcode 6.1 GM Seed 2

Update: Still applies to Xcode Version 7.3 (7D175) as of 26th April 2016

Update: Six years later Xcode 8.3 has a built-in solution. See answer below.

like image 983
Klaas Avatar asked Apr 29 '11 15:04

Klaas


People also ask

How do I delete a line in Xcode?

Delete Entire Line ( ⌘ + D ) To define custom keybindings, go to Xcode settings (press ⌘ + ,), navigate to the Key Bindings tab, and use the filter field to search for “Delete Line”. Double click into the Key field, then press your preferred key combo. I use ⌘ + D (for Delete Line).

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.


1 Answers

After a lot of search here and there, I came to the following solution:

Press and hold control key, and then press AKK.

(Note: second K deletes the empty line).

Actually it is a combination of two commands: Move to Beginning of Paragraph & Delete to End of Paragraph. You may also use/set other key(s) and also may use/set/change key bindings for other command(s) e.g. Move to Beginning of Line & Delete to End of Line. I used the above (default) key bindings as they suited me.

Edit:

To delete more than one consecutive lines, first press and hold control key, and then pressA (just to go to the beginning of the paragraph/line), then press and hold K till all the lines are deleted (this would work as the cursor remains at the beginning).

Just to make task easy (for me), I have set commandD for Delete to End of Paragraph and home/end to go to beginning/end of the paragraph.

like image 53
Vasu Avatar answered Nov 20 '22 15:11

Vasu