在以前版本的 Xcode 中,可以创建键绑定来删除当前行。有不同的解决方案,例如:
Xcode:删除行热键
Xcode 重复/删除行
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/
所有解决方案都包括修改以下文件之一:
~/Library/Application Support/Xcode/Key Bindings/*.pbxkeys
〜/ Library / KeyBindings / DefaultKeyBinding.dict
~/Library/KeyBindings/PBKeyBinding.dict
Xcode 4
中现有快捷方式的一个很好的资源是 http://cocoasamurai.blogspot.com/2011/03/xcode-4-keyboard-shortcuts-now.html 。关于删除列出了很多,但没有列出“删除行”。
但是,自 Xcode 4
以来,这些解决方案不再工作。
更新:
问题仍然与 Xcode 5.1.1
更新相同
:
问题仍然与 Xcode 6.1 GM Seed 2
更新相同
:
截至 2016 年 4 月 26 日,仍适用于 Xcode 版本 7.3 (7D175)
更新:
六年后,Xcode 8.3 有了内置解决方案。请参阅下面的答案。
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)
如果您不介意在其他应用程序中使用该键绑定,您可以尝试在常规 Cocoa 键绑定中设置它。 这有一个解释。
If you don't mind having that key binding in other apps, you could try setting it in the general Cocoa key bindings. This has an explanation.
似乎现在无法完成...如果我错了,请随时纠正我...但这是我的新解决方案...
转到 xcode 首选项,然后转到键绑定选项卡。复制默认设置,这样当我提出的建议破坏了您将使用的东西时,您就不会生我的气。
找到两个相邻的键,并且不用于您使用的任何命令...“;”,“'”也许。(我不使用命令 n 来创建新文件,所以我选择了 n,m)
设置第一个键到“移动到行开头”,第二个键到“删除到行尾”,
然后使用该序列删除一行...
替代将设置一些内容来选择行,然后只需使用删除。
seems as though it can't be done now... feel free to correct me if I am wrong... but here is my new solution...
go to xcode preferences, then the key bindings tab. duplicate the default set, so that you wont be mad at me when the suggestion that i make breaks something that you will use.
find 2 keys that are adjacent and not used for any commands that you use... ";","'" perhaps.(I don't use command n for new file, so I picked n,m)
set the first key to "Move to Begging of Line" and the second key to "Delete to end of line"
then use that sequence to delete a line...
alternate would be set something to select line, then just use delete.
XCode 5 和 6 的简单解决方案:
安装 alcatraz:http://alcatraz.io/ 然后用它来安装“XCodePlus 删除行”插件:
Window >包管理器
还有许多其他很棒的插件。
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.
首先打开Xcode->Preferences
选择Key Bindigs
然后搜索Delete
将Delete The End Of Line更改为您的快捷方式(我更喜欢 CMD + D)
这就是全部
First open Xcode->Preferences
Select Key Bindigs
Then search Delete
Change the Delete The End Of Line to your shortcut(I prefer CMD + D)
Thats All
经过大量搜索后,我得到了以下解决方案:
按住control键,然后按AKK。
(注意:第二个 K 删除空行)。
实际上它是两个命令的组合:
移至段落开头
&删除至段落末尾
。您还可以使用/设置其他键,也可以使用/设置/更改其他命令的键绑定,例如移至行首
和删除到行尾
。我使用了上面的(默认)键绑定,因为它们适合我。编辑:
要删除多于连续行,请先按住control键,然后按A(只是转到段落/行的开头),然后按住 K 直到删除所有行(这将起作用,因为光标保留在开头) 。
只是为了使任务变得简单(对我来说),我为
删除到段落末尾
和 homecommandD >/end 转到段落的开头/结尾。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.看起来 Xcode 8.3 终于添加了 Delete Line 命令
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:
Delete Line
知道了!这适用于 Xcode 4.3 到 4.5,不需要额外的应用程序,并且是 Xcode 特定的。
此解决方案与此处描述的 Duplicate Line 命令基本相同:
编辑 plist 文件,
位于/Applications/Xcode.app/Contents/Frameworks/IDEKit.framework/Resources/IDETextKeyBindingSet.plist
请注意:
添加新的
元素将此文本添加到< 结束位置的上方/code> 位于此文件底部
请注意:
的内部,因此有一个保存并打开 Xcode
在 Xcode 中添加新的键绑定
请参阅 链接答案中的屏幕截图 或执行以下操作:
这应该可以做到,但有一点需要注意。我永远无法让 Xcode 保存新绑定。
略有不同:
多么啰嗦啊,嗯?但它有效。现在,我已将 Ctrl+D 映射为删除 Lion 上 Xcode 4.3 中的整个当前行。
Got it! This works in Xcode 4.3 through 4.5 and requires no extra applications and is Xcode specific.
This solution is basically the same as the Duplicate Line command described here:
Edit the plist file
It's at /Applications/Xcode.app/Contents/Frameworks/IDEKit.framework/Resources/IDETextKeyBindingSet.plist
Note that:
Add a new
<dict>
elementAdd this text just ABOVE the close of the
<dict>
at the bottom of this fileNote that:
<dict>
so there is a</dict></plist>
after thisSave this and open Xcode
Add a new key binding in Xcode
See the screenshots for this in the linked answer or do this:
This should do it but for one caveat. I could never get Xcode to save the new binding.
The same problem is described here though my workaround had a slight variation:
What a rigmarole, eh? But it works. Now I have Ctrl+D mapped to delete the entire current line in Xcode 4.3 on Lion.
我找到了 Xcode 9 的临时解决方法。
打开 Xcode/Content/Frameworks/IDEKit.framework/Resources/IDETextK eyBindingSet.plist 并添加以下行。
它模仿 Xcode 8 中发生的操作,但支持有限。它只能删除一行,但我已经很满意了。我希望这个问题能尽快得到解决。
重新启动 Xcode 后,您可以在
Key Bindings
中看到自定义项,如下所示。绑定并使用它!
编辑)
我认为下面的比原来的更好。
I found a temporary workaround for Xcode 9.
Open the Xcode/Content/Frameworks/IDEKit.framework/Resources/IDETextKeyBindingSet.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.
After restart Xcode, you can see the customed item in
Key Bindings
like below.Bind and use it!
Edit)
I think below one is better than original one.
我使用 BetterTouchTool,它非常酷:
I use BetterTouchTool, it's pretty cool:
Rhubarb 的答案是正确的并且有效,但一件事是,plist 文件中有更简单的命令。
请遵循 Rhubarb 的所有说明,但
不要
使用下面的
说明。这样更清楚,并消除任何故障的可能性。
我想写这个作为评论,但我的“声誉”不允许我这样做。
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
use below
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.
试试这个:
首先打开Xcode->首选项
选择Key Bindigs >
搜索删除段落
更改删除将段落更改为快捷方式
try this:
First open Xcode->Preferences
Select Key Bindigs
search Delete Paragraph
Change Delete Paragraph to your shortcut
如果您是 Keyboard Maestro 用户,只需创建一个执行以下操作的宏:
我将其分配给 Command-D,并使其仅在 Xcode 中可用。
If you are a Keyboard Maestro user, just create a macro that does the following:
I assigned it to Command-D, and made it available only in Xcode.
看起来 XCode 现在使用 plist 文件而不是 dict 文件,并且新格式不支持向键绑定添加多个命令。似乎也没有办法添加自定义命令来绑定到两者。我发现实现某些功能的唯一方法是为单独的操作设置键绑定,例如为
deleteToEndOfLine:
设置^D
,然后为^L
formoveToBeginningOfLine:
,为您提供^L+^D
以获得组合效果。It looks as though XCode now uses a plist file versus a dict file, and the new format doesn't support adding multiple commands to a key binding. There also doesn't appear to be a way to add custom commands to bind to either. The only way I've found to get something working is by setting a key binding for the separate actions, such as
^D
fordeleteToEndOfLine:
, then^L
formoveToBeginningOfLine:
, giving you^L+^D
to give you the combined effect.