97

In Sublime Text, it's easy to select the next instance of a word by pressing command + d and also place multiple cursors by pressing command & clicking. I know I'm not alone in saying this is an incredibly useful function in editors.

I haven't had any luck in finding any key mappings or Alcatraz plugins for this, so I was interested to see if either there is a way to do this in xcode 5 which I might have missed or if there are plans to implement this in xcode 6?

If there isn't, and any xcode developers see this, would love to see this as a feature and hear your opinions on it :)

Matt Rowles
  • 7,721
  • 18
  • 55
  • 88

8 Answers8

118

It is possible starting from Xcode 10 Beta 3

You can add selections for the next and previous find results using the “Find and Select Next” and “Find and Select Previous” menu commands.

Additionally, you can quickly add selections for the next and previous occurrences of the current selected text using the “Select Next Occurrence” and “Select Previous Occurrence” menu commands.

E to select next occurence of currently selected

E to select previous occurence of currently selected

G to find and select next

G to find and select previous

You can also use the Find menu to find these actions. Of course, feel free to bind it to different hotkeys!

Robin Daugherty
  • 7,115
  • 4
  • 45
  • 59
Infinity
  • 3,695
  • 2
  • 27
  • 35
47

If what you're wanting to do is change the name of a variable, then when your cursor is on the variable press control+command+E and type away. (This is "Edit All in scope")

For editing on a Project scope there is always the Editor > Refactor > Rename menu item

Max Chuquimia
  • 7,494
  • 2
  • 40
  • 59
  • 5
    Thanks! Not quite what I was looking for unfortunately, but this is probably as close as we'll get at the moment. – Matt Rowles Jul 23 '14 at 00:19
  • That solves the issue only sometimes - perhaps I want to append `<< std::endl` to multiple places, for example. – OJFord Nov 27 '14 at 21:09
  • @OllieFord It would often work in the case you described.. it selects all instances of what you selected but it doesn't care if you add spaces and such. But perhaps what you're trying to point out is that you wouldn't want the text after every use of the variable – csga5000 Jan 06 '16 at 20:42
23

Highlight the word you'd like to get the next instance, then press:

+ E

and

+ G.

Continuing to press + G will cycle through all instances of the word you pressed + E on.

I have more xcode shortcuts on my site that I sometimes reference.

Sohail
  • 588
  • 4
  • 6
  • 5
    Yeah, but this only finds the next instance, it doesn't give you the ability to place a new cursor at each instance as you go. – Matt Rowles Sep 19 '15 at 04:03
16

You can create cursors with Shift + Ctrl + Mouse Click wherever you need more cursor

You can either use Shift + Ctrl + (or ) if you want to create a new cursor on the following line.

Option + Mouse Drag also works very well

Alex
  • 448
  • 6
  • 11
6

I just read on twitter that Xcode team has added multiple cursors feature for testing, but kept it hidden.To enable it use following command.

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

Link for your reference. Multiple Cursor in Xcode

Community
  • 1
  • 1
Vaibhav
  • 865
  • 2
  • 10
  • 19
5

Apple just released Xcode 10 beta with the following feature:

The Xcode Source Editor now supports multi-cursor editing allowing you to quickly edit multiple ranges of code at once. You can place additional cursors with the mouse via ⌃+⇧+Click or with column select (⌥+Click+Drag), or with the keyboard using ⌃+⇧+Up to column select up or ⌃+⇧+Down to column select down. (12564506)

Jordan Hochstetler
  • 1,308
  • 3
  • 17
  • 28
  • 1
    This is a step in the right direction, but still doesn't reveal if it's implementing next-instance-of-highlighted-code capture also. Thanks for update! – Matt Rowles Jun 09 '18 at 02:03
4

There's the Xcode-Multi-Edit-Plugin. It's still not quite like Sublime because the multiple cursors can't be used to edit beyond the selection you made when you started command-d-ing but it's close enough.

The plugin is not updated for Xcode 7.3 but this can be easily fixed by adding

    <string>ACA8656B-FEA8-4B6D-8E4A-93F4C95C362C</string>

to the list of similar UUIDs in <key>DVTPlugInCompatibilityUUIDs</key> in the plugin's Info.plist. (Found at ~/Library/Application\ Support/Developer/Shared/Xcode/Plug-ins/XcodeMultiEdit.xcplugin/Contents/Info.plist)

Another promising plug-in which currently lacks Xcode 7.3 support is Multiplex.

Daniel Schlaug
  • 1,504
  • 1
  • 13
  • 17
0

I figure a way: double click to select then click one more time to highlight all occurrences.

enter image description here

dairan
  • 26
  • 5