Multiple cursors / highlight next instance of currently highlighted word
Solution 1
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!
Solution 2
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
Solution 3
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.
Solution 4
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
Solution 5
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
Related videos on Youtube
![Matt Rowles](https://i.stack.imgur.com/cHeId.jpg?s=256&g=1)
Matt Rowles
Updated on April 14, 2021Comments
-
Matt Rowles about 3 years
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 :)
-
OJFord over 9 yearsDisappointing that this doesn't seem to be possible.
-
thumbtackthief over 9 yearsI'm shocked this doesn't have more votes. Is there any way to make feature requests that anyone knows of? For an IDE, XCode leaves a lot to be desired in terms of refactoring ability.
-
Infinity almost 6 yearsFinally available with Xcode 10 Beta 3. Added details answer below.
-
-
Matt Rowles almost 10 yearsThanks! Not quite what I was looking for unfortunately, but this is probably as close as we'll get at the moment.
-
OJFord over 9 yearsThat solves the issue only sometimes - perhaps I want to append
<< std::endl
to multiple places, for example. -
Matt Rowles almost 9 yearsYeah, 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.
-
csga5000 over 8 years@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
-
Matt Rowles about 6 yearsThis 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!
-
Leonard over 5 yearsYou can also
command + left click
the word and chooseEdit all in scope
to do this! -
willcwf over 4 years
option
on mac keyboards instead ofALT