objective-c Xcode:删除行热键
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/476953/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Xcode: Delete line hot-key
提问by typeoneerror
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?
我正在寻找一种方法来映射一些热键以在 Xcode 中“删除我的光标所在的行”。我在文本键绑定中找到了“删除到行尾”和“删除到行首”,但是无论我选择了什么,我都缺少如何完全删除该行。TextMate 已将此功能映射到 Ctrl+Shift+D,如果可能的话,我想要同样的功能。有任何想法吗?
采纳答案by Ashley Clark
You can set up a system-wide key binding file that will apply to all Cocoa apps.
您可以设置一个适用于所有 Cocoa 应用程序的系统范围的键绑定文件。
To do what you want it should like like this:
做你想做的事情应该是这样的:
In your home folder, Library/KeyBindings/DefaultKeyBinding.dict
在您的主文件夹中,Library/KeyBindings/DefaultKeyBinding.dict
{
"^D" = (
"moveToBeginningOfLine:",
"deleteToEndOfLine:",
);
}
I believe if you only want it to apply to Xcode you can name the file PBKeyBinding.dictinstead but I didn't try that myself. You can read more about this system hereand here.
我相信如果您只想将它应用于 Xcode,您可以PBKeyBinding.dict改为命名文件,但我自己没有尝试过。您可以在此处和此处阅读有关此系统的更多信息。
回答by typeoneerror
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.dictand added the following:
谢谢你的帮助,阿什利。经过一些实验,我映射了我最喜欢的 TextMate 命令(重复行、删除行)。我创建了文件~/Library/KeyBindings/PBKeyBinding.dict并添加了以下内容:
{
"^$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.
添加的“deleteBackward:”在删除一行内容后备份一行。您也可以只使用“selectLine:”。
回答by Sebastian Juarez
As I don't always work on the same xcode I prefer not to install scripts.
因为我并不总是在同一个 xcode 上工作,所以我不想安装脚本。
Xcode uses some sub-set of emacs commands. I use this approach to quickly delete a line. ^k (control-k) deletes from the cursor to the end of the line. Doing it twice also deletes the carriage return and takes up the next line. ^a takes you to the start of the line.
Xcode 使用一些 emacs 命令的子集。我使用这种方法来快速删除一行。^k (control-k) 删除从光标到行尾。执行两次也会删除回车并占用下一行。^a 带您到行的开头。
So to delete a complete line from the beginning you can use ^a^k^k.
因此,要从头删除整行,您可以使用 ^a^k^k。
回答by mclin
I was looking for a solution to this, and I tried Ashley Clark's, but it turns out there's an easier option using an included User Script called delete Line.
我一直在寻找解决方案,我尝试了 Ashley Clark 的解决方案,但结果证明使用包含的用户脚本删除行有一个更简单的选择。
- Open the weird menu to the left of 'help' that looks like a scroll.
- Choose Edit User Scripts...
- Click the Key Bindings tab
- Expand the Text section
- Double click the ? column next to 'Delete Line' and type your hotkey. It may warn you that you stole it from some other command but that's fine.
- 打开看起来像卷轴的“帮助”左侧的奇怪菜单。
- 选择编辑用户脚本...
- 单击键绑定选项卡
- 展开文本部分
- 双击 ? “删除行”旁边的列并键入您的热键。它可能会警告您是从其他命令中窃取了它,但这很好。
Done! You can do the same for Move Line Up and Move Line Down if you're an Eclipse junkie like me.
完毕!如果您是像我这样的 Eclipse 迷,您可以对 Move Line Up 和 Move Line Down 执行相同的操作。
回答by Luca Davanzo
<key>Custom Keyword Set</key>
<dict>
<key>Delete Current Line In One Hit</key>
<string>moveToEndOfLine:, deleteToBeginningOfLine:, deleteToEndOfParagraph:</string>
</dict>
I suggest to create your customized dictonary in your file IDETextKeyBindingSet.plist.
我建议在您的文件IDETextKeyBindingSet.plist 中创建您的自定义词典。
So:
所以:
- close Xcode;
- open Terminal;
- sudo nano /Applications/Xcode.app/Contents/Frameworks/IDEKit.framework/Resources/IDETextKeyBindingSet.plist
- add new custom section, for instance code in top;
- save, exit and open Xcode;
- [Xcode > Preferences > Key Binding]
- search “Delete..” and create the new shortcut.
- 关闭Xcode;
- 打开终端;
- 须藤纳米/Applications/Xcode.app/Contents/Frameworks/IDEKit.framework/Resources/IDETextKeyBindingSet.plist
- 添加新的自定义部分,例如顶部的代码;
- 保存、退出并打开 Xcode;
- [Xcode > 首选项 > 键绑定]
- 搜索“删除..”并创建新的快捷方式。
回答by Nicronaide
If you're having trouble in modern Xcode (which I was) solution for this in Xcode 7.2 is to do what Opena mentioned here with screenshotsor in text form via Velthune's answer. Since I wanted a more direct command I simplified the command to:
如果您在现代 Xcode(我是)中遇到问题,Xcode 7.2 中的解决方案是使用屏幕截图或通过 Velthune 的答案以文本形式执行 Opena此处提到的操作。由于我想要一个更直接的命令,我将命令简化为:
selectLine:, delete:, moveToBeginningOfLine:
Of course in the Xcode's Preferences >> Key Bindings, you can just find the command double-click under the Key column and give it your own binding of Ctrl+Shift+D.
当然在 Xcode 的 Preferences >> Key Bindings 中,你可以在 Key 列下找到命令双击,并给它你自己的 Ctrl+Shift+D 绑定。
回答by Ali K?ran
For Xcode 9.0(beta), inserting customized key dictionary into IDETextKeyBindingSet.plist working fine for me.You need to restart XCode if already open and after next launch you will find new customized shortcuts under the KeyBindings menu.
对于 Xcode 9.0(测试版),将自定义键字典插入到 IDETextKeyBindingSet.plist 中对我来说效果很好。如果已经打开,您需要重新启动 XCode,下次启动后,您将在 KeyBindings 菜单下找到新的自定义快捷方式。
<key>Customized</key>
<dict>
<key>Delete Rest Of Line</key>
<string>deleteToEndOfLine:</string>
<key>Delete Line</key>
<string>moveToBeginningOfLine:, deleteToEndOfLine:</string>
<key>Duplicate Current Line</key>
<string>selectLine:, copy:, moveToEndOfLine:, insertNewline:, moveToBeginningOfLine:, paste:</string>
</dict>
回答by Ixx
This works for me (Xcode 4.4.1):
这对我有用(Xcode 4.4.1):
Same steps like described here: Xcode duplicate line(Halley's answer)
与此处描述的步骤相同:Xcode 重复行(Halley 的回答)
But instead of:
但不是:
selectLine:, copy:, moveToEndOfLine:, insertNewline:, paste:, deleteBackward:
selectLine:, copy:, moveToEndOfLine:, insertNewline:, paste:, deleteBackward:
Use:
用:
selectLine:, moveToBeginningOfLine:, deleteToEndOfLine:
selectLine:, moveToBeginningOfLine:, deleteToEndOfLine:

