75

I'm sorry, I don't find an already asked question for this problem...

in Xcode, what is the shortcut to edit multiples lines like the "CMD+click" of sublime text?

enter image description here

Damien Romito
  • 9,801
  • 13
  • 66
  • 84
  • This would be a nice feature, but I don't think it is possible. Check Alcatraz packages maybe. – Siriss Mar 31 '15 at 15:37
  • 2
    What exactly this command is for? For selecting multiple words/characters across multiple lines? If yes, you can achieve same in Xcode using "Option + Click". – gagarwal Mar 31 '15 at 16:25
  • oh? you probably changed something in the settings cause it's not works for me – Damien Romito Mar 31 '15 at 16:29
  • I was looking for this too but couldn't find a way. I ended up doing search and replace. In your example, I'd search for "self.player" and replace with "self.whateverPlayer" – Genki Jan 08 '16 at 21:51
  • Hi @DamienRomito It's been a few years since you posted this. Any chance you happened to find a way to do this? Thanks – Vladimir May 28 '17 at 02:43
  • Sorry @Vladimir, still nothing... – Damien Romito Jun 03 '17 at 20:02

5 Answers5

125

It is possible with Xcode 10+, see the wwdc2018 presentation of the functionality.

Ways to create multiple cursors:

  • ⇧ Shift + ⌃ Control + Left Mouse Click: Will create a new cursor on every click
  • ⇧ Shift + ⌃ Control + : Will create a new cursor above
  • ⇧ Shift + ⌃ Control + : Will create a new cursor bellow
  • ⌥ Option + drag: Will create a new cursor on every line you drag

preview:

enter image description here

For more information, see this answer

Daniel
  • 20,420
  • 10
  • 92
  • 149
  • Do you know if there's a way to get the cursor in let's say every other line using keyboard only? (besides placing the cursor in many adjacent rows and then pressing enter). – Andrej Dec 02 '20 at 14:41
  • I believe [shift] + [control] + left mouse click will be your best option. I don't know of any other way by k/b appart from the one that you described and that one is very unlikely to be useful. – Daniel Dec 29 '20 at 09:11
12

I'm not sure how helpful this is to you, but if you want to change a variable name, you can click it, hover over it until the triangle dropdown button appears, click it and select Edit All in Scope.

This allows you to change all instances of that variable name.

enter image description here

SaravInfern
  • 3,338
  • 1
  • 20
  • 44
Jace Tan
  • 363
  • 2
  • 12
9

Multiline editing is supported in Xcode 10, Ctrl + Shift + click the lines you want to edit.

RoyR
  • 169
  • 3
  • 3
1

Select the line you want to edit, then press option + command for a moment demo

Iwo Kucharski
  • 3,735
  • 3
  • 50
  • 66
Gpx
  • 13
  • 3
0

I had this same question a few weeks ago, if you use the Option Key you can use column select and edit multiple lines like in your picture. Where the confusion comes in is it is used for multiple things. If you click the option key over a variable or text it shows a question mark and shows information about what you click on. However, if you hold the option key while before the line or not over text it shows up as a plus symbol and you can drag and select multiple lines and edit them at the same time.

Zack
  • 1
  • 1
  • 1