Sunday, April 29, 2018

Multiple Cursors in Xcode

Daniel Martín:

For the new refactoring engine, the Xcode team developed a simple implementation for testing, but kept it disabled:

defaults write PegasusMultipleCursorsEnabled -bool true

Press Command and click/select some text and the editor will create a new cursor.

Any edits that you make are then repeated by all the cursors simultaneously. This can make certain batch changes faster and more reliable than doing them one-by-one, and for many common cases it’s easier (and requires less of a mental context switch) than writing a regular expression or script. The Xcode implementation is difficult to use in practice, though, because when Command is down, Xcode often wants to do something with the word I’m clicking on/near, rather than letting me place the cursor. Also, the edits are not bundled into undo groups the way you would expect.

Update (2018-06-04): Ole Begemann on Xcode 10:

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

Place additional cursors via ⌃+⇧+Click or with column select (⌥+Click+Drag), or using ⌃+⇧+Up/Down.”

Update (2018-08-02): Benjamin Mayo:

Xcode 10 multiple cursors are too good not to share.

Update (2020-11-27): Dave DeLong:

Discovered a way in #Xcode to do an “edit all” that’s not limited to declarations

  1. select the thing you want to edit
  2. press-and-hold ⌥⌘E to “select next occurrence” until everything’s selected
  3. type in the replacement; all of ‘em get changed

Update (2023-02-14): Keith Harrison:

I found myself rediscovering Xcode’s multi-cursor support this week. Here’s a reminder in case you need it.

Comments RSS · Twitter

Leave a Comment