How do I create a Delete-Line Keyboard shortcut in

2019-01-16 03:40发布

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.

13条回答
聊天终结者
2楼-- · 2019-01-16 04:14

Rhubarb's answer is correct and works but one thing, there is more simple command in plist file. Follow all instructions of Rhubarb's but

instead of

<string>moveToEndOfLine:, deleteToBeginningOfLine:, deleteToEndOfParagraph:</string>

use below

<string>selectLine:, delete:</string>

This is more clear and throw away any possibility of malfunction.

I want to write this as a comment, but my "reputation" doesn't allow me to do that.

查看更多
乱世女痞
3楼-- · 2019-01-16 04:15

I found a temporary workaround for Xcode 9.

Open the Xcode/Content/Frameworks/IDEKit.framework/Resources/IDETextK‌​eyBindingSet.plist and add the lines below.

It mimics the action which happens in Xcode 8 with limited support. It only can remove just one line but I'm satisfied somehow. I hope this will be fixed soon.

<key>Customized</key>
<dict>
    <key>Delete Line</key>
    <string>moveToBeginningOfLine:, deleteToEndOfLine:, moveDown:, deleteBackward:</string>
</dict>

After restart Xcode, you can see the customed item in Key Bindings like below.

enter image description here

Bind and use it!

Edit) I think below one is better than original one.

<string>moveToEndOfLine:, deleteToBeginningOfLine:, deleteToEndOfParagraph:</string>
查看更多
做自己的国王
4楼-- · 2019-01-16 04:16

If you are a Keyboard Maestro user, just create a macro that does the following:

  • Command Left Arrow
  • Shift Down Arrow
  • Delete

I assigned it to Command-D, and made it available only in Xcode.

查看更多
【Aperson】
5楼-- · 2019-01-16 04:17

An easy solution for XCode 5 and 6:

Install alcatraz: http://alcatraz.io/ then use it to install the "XCodePlus delete line" plugin:

Window > Package manager

There are lots of other awesome plugins as well.

查看更多
Melony?
6楼-- · 2019-01-16 04:21

I use BetterTouchTool, it's pretty cool:

enter image description here

查看更多
三岁会撩人
7楼-- · 2019-01-16 04:25

Looks like Xcode 8.3 finally added the Delete Line command :)

By default, no keyboard shortcut is assigned to it, so you will need to add one yourself in:

  1. Open Xcode > Preferences > Key Bindings
  2. Search for Delete Line
  3. Add a keyboard shortcut in the Key column

Xcode Key Bindings

查看更多
登录 后发表回答