xcode Xcode重复/删除行

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/551383/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 02:58:19  来源:igfitidea点击:

Xcode duplicate/delete line

xcodelineduplicate-data

提问by Summer

Coming from Eclipse and having been used to duplicate lines all the time, it's pretty strange finding out that Xcode has no such function. Or does it?

来自 Eclipse 并且一直被用来复制行,发现 Xcode 没有这样的功能是非常奇怪的。或者是吗?

I know it's possible to change the system wide keybindings but that's not what I'm after.

我知道可以更改系统范围的键绑定,但这不是我想要的。

采纳答案by Frank Schr?der

The whole point is NOT to use the Cmd-C/Cmd-Vshortcuts. I have the same issue coming from IntelliJ, and being able to just duplicate lines with Cmd-Dand delete them with Cmd-Yis a big time saver.

重点是不要使用Cmd-C/Cmd-V快捷方式。我有来自 IntelliJ 的相同问题,并且能够只复制行Cmd-D和删除它们可以Cmd-Y节省大量时间。

It's been bugging me ever since. However, it looks like someone else has found a solutionthat works.

从那以后就一直困扰着我。但是,看起来其他人已经找到了有效的解决方案

In short, create a file ~/Library/KeyBindings/PBKeyBinding.dictwith the following content and restart Xcode.

简而言之,创建一个~/Library/KeyBindings/PBKeyBinding.dict包含以下内容的文件并重新启动Xcode。

{
    "^$K" = (
        "selectLine:",
        "cut:"
    );

    "^$D" = (
        "selectLine:",
        "copy:",
        "moveToEndOfLine:",
        "insertNewline:",
        "paste:",
        "deleteBackward:"
    );
}

This will create two shortcuts: Ctrl-Shift-Kfor deleting the current line and Ctrl-Shift-Dfor duplicating the current line. Please note that this will onlywork if you are NOTusing a custom key binding set in Xcode. Switch to "XCode Default" and things should work. Tested on XCode 3.2 on Snow Leopard.

这将创建两个快捷方式:Ctrl- Shift-K用于删除当前行和Ctrl- Shift-D用于复制当前行。请注意,这只是如果你的工作使用自定义键在Xcode绑定设置。切换到“XCode Default”,事情应该可以正常工作了。在雪豹上的 XCode 3.2 上测试。

More information on Mac OS X key bindings: http://funkworks.blogspot.it/2013/03/republishing-of-wwwerasetotheleftcompos.html

有关 Mac OS X 键绑定的更多信息:http: //funkworks.blogspot.it/2013/03/republishing-of-wwwerasetotheleftcompos.html

回答by Tom Alsberg

To delete a line: Ctrl-Ato go to the beginning of the line, then Ctrl-Kto delete it, and another time Ctrl-Kto remove the empty line. (I do not use Xcode very often, but I'm used to that in Emacs and other text inputs with Emacs-like bindings, and it seems to work in Xcode too.)

删除一行Ctrl-A转到该行的开头,然后Ctrl-K删除它,再一次Ctrl-K删除空行。(我不经常使用 Xcode,但我已经习惯了在 Emacs 和其他具有类似 Emacs 绑定的文本输入中使用它,而且它似乎也适用于 Xcode。)

And to duplicate a line: I don't know of many programs that have a command for that, but usually I just use Copy+Paste - in Xcode it's CUA-like: Ctrl+Ato go to the beginning of the line, Shift+to select it, Command+Cto copy and Command+*Vto paste twice (once overriding the line and once appending to it).

并复制一行:我不知道有很多程序有这个命令,但通常我只使用复制+粘贴 - 在 Xcode 中它类似于 CUA: Ctrl+A转到行的开头,Shift+选择它,Command+C复制和Command+*V粘贴两次(一次覆盖该行,一次附加到它)。

(from a person that types and edits text all the time, so often in different programs, and occasionally gets pissed at having to distract himself with a dumb widget while making a little correction in a text input, that he just cannot avoid remembering these sequences and habits)

(来自一个一直在输入和编辑文本的人,经常在不同的程序中,偶尔会因为不得不用一个愚蠢的小部件分散自己的注意力而对文本输入进行一点修正而生气,他就是无法避免记住这些序列和习惯)

回答by Opena

Delete a line like eclipse CTRL+D(tested on Xcode 4.5.1) :

删除像 eclipse CTRL+这样的一行D(在 Xcode 4.5.1 上测试过):

First of all, change these rights :

首先,更改这些权限:

sudo chmod 666 /Applications/Xcode.app/Contents/Frameworks/IDEKit.framework/Resources/IDETextKeyBindingSet.plist

sudo chmod 777 /Applications/Xcode.app/Contents/Frameworks/IDEKit.framework/Resources/

Open /Applications/Xcode.app/Contents/Frameworks/IDEKit.framework/Resources/IDETextKeyBindingSet.plistwith Xcode himself and add this new entry :

/Applications/Xcode.app/Contents/Frameworks/IDEKit.framework/Resources/IDETextKeyBindingSet.plist自己用 Xcode打开并添加这个新条目:

deleteToBeginningOfLine:, moveToEndOfLine:, deleteToBeginningOfLine:, deleteBackward:, moveDown:, moveToBeginningOfLine:

enter image description here

在此处输入图片说明

Restart Xcode and open Xcode > Preferences > KeyBindings. Find your macro and define a shortkey :

重新启动 Xcode 并打开 Xcode > Preferences > KeyBindings。找到你的宏并定义一个快捷键:

enter image description here

在此处输入图片说明

回答by leviathan

I tried the key bindings solution, but it I couldn't get it to work. However editing my XCode key bindings works like a charm. Here's how I made it.

我尝试了键绑定解决方案,但我无法让它工作。然而,编辑我的 XCode 键绑定就像一个魅力。这是我如何做到的。

This solution does not alter the contents of the Clipboard!

此解决方案不会更改剪贴板的内容!

Open the XCode Key Bindings:

打开 XCode 键绑定:

alt text

替代文字

In the Edit User Scripts Dialog:

在编辑用户脚本对话框中:

  1. Duplicate the "Move Line Down" script and rename it
  2. Duplicate the "Move Line Down.scpt" file, rename the script, select file via (double click) in Script Editor
  3. Edit the script (Opens "AppleScript Editor") and remove the "delete (paragraphs startLine through endLine)" passage.
  4. If you do not want to restart XCode, you seem to have to remove and re-add the script. Be sure that you have "Output" set to "Discard Output", otherwise you will have a "(null)" in your source file
  5. I slightly modified the scripts a little bit more to have the right lines selected:
  1. 复制“Move Line Down”脚本并重命名
  2. 复制“Move Line Down.scpt”文件,重命名脚本,通过(双击)在脚本编辑器中选择文件
  3. 编辑脚本(打开“AppleScript 编辑器”)并删除“删除(从 startLine 到 endLine 的段落)”段落。
  4. 如果您不想重新启动 XCode,您似乎必须删除并重新添加脚本。确保将“输出”设置为“丢弃输出”,否则源文件中将出现“(空)”
  5. 我稍微修改了脚本以选择正确的行:

Duplicate Line Up:

重复排队:

using terms from application "Xcode"
tell first text document
    set {startLine, endLine} to selected paragraph range

    if startLine > 1 then
        set theText to (paragraphs startLine through endLine)
        set theText to (theText as string)
        make new paragraph at beginning of paragraph (startLine) with data theText
        set selected paragraph range to {endLine + 1, endLine + endLine - startLine + 1}
    else
        beep 1
    end if
end tell
end using terms from

Duplicate Line Down:

重复行向下:

using terms from application "Xcode"
tell first text document
    set {startLine, endLine} to selected paragraph range
    if endLine < (count paragraphs) then
        set theText to (paragraphs startLine through endLine)
        set theText to (theText as string)
        (* delete (paragraphs startLine through endLine) *)
        make new paragraph at beginning of paragraph (endLine + 1) with data theText
        set selected paragraph range to {startLine, endLine}
    else
        beep 1
    end if
end tell
end using terms from

alt text

替代文字

回答by Joakim

OK, so I had this working for a while and then suddenly it broke. Now I have combined from different posts here and found a solution that works for XCode 6.3.1.

好的,所以我让这个工作了一段时间,然后突然它坏了。现在我结合了这里不同的帖子,找到了一个适用于 XCode 6.3.1 的解决方案。

  1. Go to /Applications/Xcode.app/Contents/Frameworks/IDEKit.framework/Versions/A/with Finder.

  2. find the folder named Resources. Right Click it, press Get Info, unlock the sharing & permissions setting (By pressing the lock) and set it to Read & Write for all.

  3. Enter the folder and find the file IDETextKeyBindingSet.plist. Right Click it, press Get Info, unlock the sharing & permissions setting (By pressing the lock) and set it to Read & Write for all.

  4. Open the file with XCode (Default)

  5. Find deletions, right click and add a new row. Name it for example Delete Line. In the value field, type: selectLine:, deleteBackward:. (This can also be done for duplicate line: selectLine:,copy:,moveToEndOfLine:,insertNewline:,paste:,deleteBackward:)

  1. /Applications/Xcode.app/Contents/Frameworks/IDEKit.framework/Versions/A/使用 Finder前往。

  2. 找到名为 Resources 的文件夹。右键单击它,按获取信息,解锁共享和权限设置(通过按锁)并将其设置为所有人的读取和写入。

  3. 进入文件夹,找到文件IDETextKeyBindingSet.plist。右键单击它,按获取信息,解锁共享和权限设置(通过按锁)并将其设置为所有人的读取和写入。

  4. 使用 XCode 打开文件(默认)

  5. 查找删除,右键单击并添加新行。将其命名为例如删除行。在值字段中,键入:selectLine:, deleteBackward:。(这也有重复的线路进行:selectLine:,copy:,moveToEndOfLine:,insertNewline:,paste:,deleteBackward:

  1. Start XCode, go to preferences / keybindings and search for Delete Line. Set shortcut. Enjoy.
  1. 启动 XCode,转到首选项/键绑定并搜索删除行。设置快捷方式。享受。

回答by raheel

As Xcode 4 makes this difficult to implement using key bindings, I have resorted to using Keyboard Maestro(Quickeysshould work well too, but it's not fully Lion compatible). For e.g., here is my Keyboard Maestro shortcut (bound to ?-?-D):

由于 Xcode 4 使用键绑定很难实现这一点,因此我求助于使用键盘大师Quickeys应该也能很好地工作,但它不完全兼容 Lion)。例如,这是我的键盘大师快捷键(绑定到?-?-D):

http://bit.ly/thC6yf

http://bit.ly/thC6yf

回答by Laurent Meyer

I know that this thread is quite old but I found another solution using BetterTouchTool, you can execute the Ctrl+A, Ctrl+K, Ctrl+Ksequence in one shortcut by configuring like this in BTT:

我知道这个线程已经很老了,但我找到了另一种使用BetterTouchTool 的解决方案,您可以通过在 BTT 中这样配置来在一个快捷方式中执行Ctrl+ ACtrl+ KCtrl+K序列:

enter image description here

在此处输入图片说明

(Use the Attach Additional Action Button to append the second and third shortcut)

(使用附加附加操作按钮附加第二个和第三个快捷方式)

PS: Coming from Eclipse where Cmd+Dis delete line ^^

PS:来自 Eclipse,其中Cmd+D是删除行 ^^

回答by Gagandeep Gambhir

To Delete Line in Xcode 10.1, please follow the steps of below screenshot to add a shortcut key.

要在 Xcode 10.1 中删除行,请按照以下屏幕截图的步骤添加快捷键。

enter image description here

在此处输入图片说明

回答by Damien Flament

Use user scripts.

使用用户脚本。

There are scripts to move and delete lines yet. You have to define key binds for those scripts (menu Scripts-> Edit User Scripts..., under xCode 3.2).

有脚本可以移动和删除行。您必须为这些脚本定义键绑定(在 xCode 3.2 下,菜单Scripts-> Edit User Scripts...)。

To duplicate line, you have to make your own script. But it's very simple ! Duplicate the "Move Line Down" script and remove the line which delete selected text :

要复制行,您必须制作自己的脚本。但这很简单!复制“Move Line Down”脚本并删除删除所选文本的行:

delete (paragraphs startLine through endLine)

回答by Paul Tomblin

Triple click to select the whole line, command-c to select and command-v twice to duplicate it. It's not an Xcode function, it's just part of the OS.

三次单击以选择整行, command-c 选择和 command-v 两次复制它。它不是 Xcode 的功能,它只是操作系统的一部分。