Xcode 10 中的多光标编辑

Multi-cursor editing in Xcode 10

Xcode10 编辑器中的'Multi-cursor editing'是什么。 (更多信息在release notes中提到但无法理解。)

具体是如何工作的?

To edit multiple instances of text within different sections of a document, you can use multi-cursor editing. This allows multiple cursors to be placed in different spots so text can be added, modified, or deleted.

它是 Source Editor 的名字,为了参考,我从 whats-new-in-xcode10 and Sample link 1 and Sample link 2

那里得到了答案

The Xcode 10 Source Editor now supports multi-cursor editing allowing you to quickly edit multiple ranges of code at once.

  • shift + control + 点击
  • shift + control +
  • shift + control +
  • 选项 + 拖动

With a source control-enabled project the source editor displays changes made by a developer in the gutter and shows changes made by other developers that haven’t yet been pulled into the project

Shift + Ctrl + 单击 当您希望多次编辑文件中的相同文本时 例如

    option_A.isEnabled = false
    option_B.isEnabled = false
    option_C.isEnabled = false
    option_D.isEnabled = false

在这里,我必须在所有四行上都设置为真,然后最好使用 shift + [=16= 立即设置为真]control + 点击而不是编辑每一行

最好的使用方法是使用 Find 菜单中的 Select Next Occurrence 命令。

它的默认键盘快捷键是alt + cmd + e,但你可以设置它到 cmd + d 来模仿 Sublime Text 的行为。

这样,您可以编辑不同的代码行,而其他答案中的解决方案只允许您编辑相似的行。

例如,如果您有此代码:

NSString *myStringg = @"stringg";
// print the stringg
NSLog(@"Here is my stringg: %@", myStringg);

你只需:

  1. 手动select 使用光标从第一行开始第一个 Stringg 出现
  2. Select Next Occurrence 的键盘快捷键 4 次
  3. 箭头键
  4. 点击退格

你将拥有:

NSString *myString = @"string";
// print the string
NSLog(@"Here is my string: %@", myString);

对于像我这样使用 cmd + Shift + L[= 的人来说,还有一个键盘快捷键可用22=] 在 Sublime 中。

叫做Selection - Split Selection By Lines。我将它设置为 cmd + Shift + L 但我必须设置 Show Library我不用来解决冲突的其他随机快捷方式。

用法

(1) 编辑编码键

使用 选项 ⌥ + 拖动

(2) 编辑方法参数缩进

使用 Shift ⇧ + Control ⌃ + 单击

相关默认值

$ defaults write com.apple.dt.Xcode PegasusMultipleCursorsEnabled -bool true

参考

  1. https://sarunw.com/posts/multi-cursor-editing-in-xcode/
  2. https://github.com/ctreffs/xcode-defaults
  3. Mac 键盘快捷键 https://support.apple.com/en-us/HT201236