Xcode 10 中的多光标编辑

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

Multi-cursor editing in Xcode 10

xcodexcode10multicursorediting

提问by Krunal

What is 'Multi-cursor editing' in Xcode 10 editor. (more information about the same is mentioned in release notesbut unable to understand.)

什么是 Xcode 10 编辑器中的“多光标编辑”。(发行说明中提到了有关相同的更多信息,但无法理解。)

How exactly does it work?

它究竟是如何工作的?

回答by Anbu.Karthik

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.

要在文档的不同部分编辑多个文本实例,您可以使用多光标编辑。这允许将多个光标放置在不同的位置,以便可以添加、修改或删除文本。

its the name of Source Editor, for reference purpose I taken the answer from whats-new-in-xcode10and Sample link 1and Sample link 2

它是Source Editor的名称,出于参考目的,我从whats-new-in-xcode10Sample link 1Sample link 2 中得到了答案

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

Xcode 10 源代码编辑器现在支持多光标编辑,允许您一次快速编辑多个范围的代码。

  • shift+ control+ click
  • shift+ control+
  • shift+ control+
  • option+ drag
  • shift+ control+ 点击
  • shift+ control+
  • shift+ control+
  • option+ 拖动

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

对于启用源代码控制的项目,源代码编辑器会在装订线中显示开发人员所做的更改,并显示其他开发人员所做的尚未加入项目的更改

回答by Iulian Onofrei

The best way to use it is by using the Select Next Occurrencecommand from the Findmenu.

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

Its default keyboard shortcut is alt+ cmd+ e, but you could set it to cmd+ dto mimic Sublime Text's behavior.

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

This way, you can edit code lines that are different, whereas the solutions in the other answers only allow you to edit similar lines.

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

For example, if you have this code:

例如,如果您有以下代码:

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

you simply:

你只需:

  1. manually select the first Stringgoccurrence from the first line using the cursor
  2. hit the Select Next Occurrence's keyboard shortcut 4 times
  3. hit the rightarrow key
  4. hit backspace
  1. Stringg使用光标手动选择第一行中的第一次出现
  2. Select Next Occurrence4 次 的键盘快捷键
  3. right箭头键
  4. backspace

and you'll have:

你将拥有:

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

回答by jagdeep singh

Shift+ Ctrl+ click when you wish to edit same text in file for multiple times e.g

Shift+ Ctrl+click 当你想编辑同一个文本文件中多次如

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

in this i have to put true on all four lines then it should be better for to put true at once by using shift+ control+ clickrather than edit each line

在这方面,我必须把真正对所有四行那么它应该是更好地为通过把真正的一次shift+ control+click,而不是编辑的每一行

回答by Sonastra

There is also a keyboard shortcut available for those like me who use cmd+ Shift+ Lin Sublime.

也有可为那些像我这样谁使用键盘快捷键cmd+ Shift+L中的崇高。

It's called Selection - Split Selection By Lines. I set it to cmd+ Shift+ Lbut I had to set the Show Libraryshortcut to something else random that I don't use to resolve the conflict.

它被称为Selection - Split Selection By Lines。我将它设置为cmd+ Shift+ L,但我不得不设置Show Library快捷方式到别的东西随便,我不使用,以解决冲突。