如何在 Xcode 8 中创建删除行键盘快捷键? Xcode 3 解决方案不再起作用

发布于 2024-11-04 06:51:30 字数 1456 浏览 6 评论 0 原文

在以前版本的 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(13

叫思念不要吵 2024-11-11 06:51:38

如果您不介意在其他应用程序中使用该键绑定,您可以尝试在常规 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.

国际总奸 2024-11-11 06:51:38

似乎现在无法完成...如果我错了,请随时纠正我...但这是我的新解决方案...

转到 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.

醉城メ夜风 2024-11-11 06:51:38

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.

给不了的爱 2024-11-11 06:51:38

首先打开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 AllHere is the screenshot

夏雨凉 2024-11-11 06:51:37

经过大量搜索后,我得到了以下解决方案:

按住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.

御守 2024-11-11 06:51:37

看起来 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:

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

Xcode Key Bindings

终难愈 2024-11-11 06:51:37

知道了!这适用于 Xcode 4.3 到 4.5,不需要额外的应用程序,并且是 Xcode 特定的。

此解决方案与此处描述的 Duplicate Line 命令基本相同:

编辑 plist 文件,

位于/Applications/Xcode.app/Contents/Frameworks/IDEKit.framework/Resources/IDETextKeyBindingSet.plist

请注意:

  • 链接的答案建议为此使用 Xcode,但我发现这会使 Xcode 崩溃
  • 此路径适用于 Lion - 对于其他路径可能有所不同 的操作系统版本
  • 您可能需要 sudo 或更改权限才能编辑此文件
  • 在编辑之前关闭 Xcode

添加新的 元素

将此文本添加到 < 结束位置的上方/code> 位于此文件底部

    <key>Custom</key>
    <dict>
      <key>Delete Current Line In One Hit</key>
      <string>moveToEndOfLine:, deleteToBeginningOfLine:, deleteToEndOfParagraph:</string> 
    </dict>

请注意:

  • 这是现有 内部,因此有一个
  • 这会将命名操作“Delete Current Line In One Hit”与字符串中的三个关键操作相关联。我在这里尝试了不同的选项以获得正确的组合。例如,如果您尝试 moveToBeginningOfLine、deleteToEndOfLine 而不是相反,则在空行上使用它会删除该行和整个下一行。这是令人不愉快的

保存并打开 Xcode

在 Xcode 中添加新的键绑定

请参阅 链接答案中的屏幕截图 或执行以下操作:

  1. 打开 Xcode 首选项
  2. 选择按键绑定
  3. 单击全部
  4. 在搜索框中键入“删除”并搜索“一键删除当前行”
  5. 添加新绑定。

这应该可以做到,但有一点需要注意。我永远无法让 Xcode 保存新绑定。
略有不同:

  1. 此处描述了相同的问题,尽管我的解决方法 默认绑定的副本(点击“绑定”窗口左下角的 + 按钮并创建副本)
  2. 在副本中设置新绑定
  3. 关闭首选项对话框(这就是变体!)
  4. 再次打开首选项并创建新的副本旧的重复项并删除旧的重复项。

多么啰嗦啊,嗯?但它有效。现在,我已将 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:

  • the linked answer suggests using Xcode for this, but I find that this crashes Xcode
  • this path is for Lion - it may vary for other OS versions
  • you may have to sudo or change permissions to edit this file
  • close Xcode before editing

Add a new <dict> element

Add this text just ABOVE the close of the <dict> at the bottom of this file

    <key>Custom</key>
    <dict>
      <key>Delete Current Line In One Hit</key>
      <string>moveToEndOfLine:, deleteToBeginningOfLine:, deleteToEndOfParagraph:</string> 
    </dict>

Note that:

  • This is inside the existing <dict> so there is a </dict></plist> after this
  • This associates the named action "Delete Current Line In One Hit" to the three key actions in the string. I played around with different options here to get the right combination. For instance, if you try moveToBeginningOfLine, deleteToEndOfLine instead of vice versa, then using it on empty lines will delete the line and the entire next line. Which is unpleasant

Save this and open Xcode

Add a new key binding in Xcode

See the screenshots for this in the linked answer or do this:

  1. Open Xcode Preferences
  2. Select Key Bindings
  3. Click on All
  4. In the Search box type "Delete" and search for "Delete Current Line in One Hit"
  5. Add your new binding.

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:

  1. Create a duplicate of the Default bindings (hit the + button at the bottom left of the Bindings window and create a duplicate)
  2. Set the new binding in the duplicate
  3. Close the preference dialog (that's the variation!)
  4. Open preferences again and make a new duplicate of the old duplicate and delete the old duplicate.

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.

桃扇骨 2024-11-11 06:51:37

我找到了 Xcode 9 的临时解决方法。

打开 Xcode/Content/Frameworks/IDEKit.framework/Resources/IDETextK‌ eyBindingSet.plist 并添加以下行。

它模仿 Xcode 8 中发生的操作,但支持有限。它只能删除一行,但我已经很满意了。我希望这个问题能尽快得到解决。

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

重新启动 Xcode 后,您可以在 Key Bindings 中看到自定义项,如下所示。

输入图像描述这里

绑定并使用它!

编辑)
我认为下面的比原来的更好。

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

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>
秋风の叶未落 2024-11-11 06:51:37

我使用 BetterTouchTool,它非常酷:

在此处输入图像描述

I use BetterTouchTool, it's pretty cool:

enter image description here

知你几分 2024-11-11 06:51:37

Rhubarb 的答案是正确的并且有效,但一件事是,plist 文件中有更简单的命令。
请遵循 Rhubarb 的所有说明,但

不要

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

使用下面的

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

说明。这样更清楚,并消除任何故障的可能性。

我想写这个作为评论,但我的“声誉”不允许我这样做。

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.

淡墨 2024-11-11 06:51:37

试试这个:

  1. 首先打开Xcode->首选项

  2. 选择Key Bindigs >

  3. 搜索删除段落

  4. 更改删除将段落更改为快捷方式

在此处输入图像描述

try this:

  1. First open Xcode->Preferences

  2. Select Key Bindigs

  3. search Delete Paragraph

  4. Change Delete Paragraph to your shortcut

enter image description here

方觉久 2024-11-11 06:51:37

如果您是 Keyboard Maestro 用户,只需创建一个执行以下操作的宏:

  • Command 左箭头
  • Shift 下箭头
  • 删除

我将其分配给 Command-D,并使其仅在 Xcode 中可用。

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.

残月升风 2024-11-11 06:51:37

看起来 XCode 现在使用 plist 文件而不是 dict 文件,并且新格式不支持向键绑定添加多个命令。似乎也没有办法添加自定义命令来绑定到两者。我发现实现某些功能的唯一方法是为单独的操作设置键绑定,例如为 deleteToEndOfLine: 设置 ^D,然后为 ^L for moveToBeginningOfLine:,为您提供 ^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 for deleteToEndOfLine:, then ^L for moveToBeginningOfLine:, giving you ^L+^D to give you the combined effect.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文