Multi-cursor editing in Xcode 10

XcodeXcode10Multicursorediting

Xcode Problem Overview


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

How exactly does it work?

Xcode Solutions


Solution 1 - Xcode

> 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-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 + click
  • shift + control +
  • shift + control +
  • option + drag

>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

Solution 2 - Xcode

The best way to use it is by using the Select Next Occurrence command from the Find menu.

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

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 Stringg occurrence from the first line using the cursor
  2. hit the Select Next Occurrence's keyboard shortcut 4 times
  3. hit the right arrow key
  4. hit backspace

and you'll have:

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

Solution 3 - Xcode

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

    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 + click rather than edit each line

Solution 4 - Xcode

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

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

Solution 5 - Xcode

Usages

(1) Edit CodingKey

using Option ⌥ + drag

demo-1

(2) Edit method parameter indentation

using Shift ⇧ + Control ⌃ + click

demo-2

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

Reference

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionKrunalView Question on Stackoverflow
Solution 1 - XcodeAnbu.KarthikView Answer on Stackoverflow
Solution 2 - XcodeIulian OnofreiView Answer on Stackoverflow
Solution 3 - Xcodejagdeep singhView Answer on Stackoverflow
Solution 4 - XcodeSonastraView Answer on Stackoverflow
Solution 5 - XcodeGeorgeView Answer on Stackoverflow