I have the this code:
selectedUser.firstName
selectedUser.lastName
selectedUser.age
selectedUser.foneNumber
I want to select the block (4 lines simultaneous)
selectedUser
selectedUser
selectedUser
selectedUser
and then replace from selectedUser
to user
(expected result)
user.firstName
user.lastName
user.age
user.foneNumber
How to do block selection (column selection) in XCode?
2
Answers
Click before the start of the first
object
.Shift-control-click before the start of the second
object
(or shift-control-down-arrow).Shift-control-click before the start of the third
object
(or shift-control-down-arrow).You are now editing three lines simultaneously.
Control-right-arrow to jump past
object
, and type.main.
Shift-right-arrow to select the next letter. Edit > Format > Transformations > Make Lowercase.
Command-right-arrow to jump the end, and type
.description
In addition to shift–control-clicking the individual occurrences, you can hold option key while selecting the range:
Here I option-selected the
selectedU
portion and then pressed u to replace that with the letter “u” on all lines. From there, it proceeds much as matt outlined.But, bottom-line, I shift–control-click when I want individual, multiple cursors, but they might not vertically line up or might not be contiguous. I use option-select when they do line up nicely, as in your example, saving me a few individual clicks.
Paul Hudson has a video on multiple cursors. That’s #32 on his Xcode tips and tricks.
Your revised question amounts to a renaming a property or variable. That suggests two other options, too:
A slightly broader “rename” of a property: select any occurrence of the property name and press control–command–e. Then edit the current occurrence and they’ll all change. Hit return to save the change.
Note that renamed the property as well as the four occurrences in that function.
If you want the renaming to scan your whole project for occurrences to rename, go to Xcode “Editor” » “Refactor” » “Rename”:
This is #14 in Paul’s little series.