skip to Main Content

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


    1. Click before the start of the first object.

    2. Shift-control-click before the start of the second object (or shift-control-down-arrow).

    3. Shift-control-click before the start of the third object (or shift-control-down-arrow).

      You are now editing three lines simultaneously.

    4. Control-right-arrow to jump past object, and type .main.

    5. Shift-right-arrow to select the next letter. Edit > Format > Transformations > Make Lowercase.

    6. Command-right-arrow to jump the end, and type .description

    Login or Signup to reply.
  1. In addition to shiftcontrol-clicking the individual occurrences, you can hold option key while selecting the range:

    option-select

    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 shiftcontrol-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:

    1. A slightly broader “rename” of a property: select any occurrence of the property name and press controlcommande. Then edit the current occurrence and they’ll all change. Hit return to save the change.

      control-command-e

      Note that renamed the property as well as the four occurrences in that function.

    2. If you want the renaming to scan your whole project for occurrences to rename, go to Xcode “Editor” » “Refactor” » “Rename”:

      refactor-rename

      This is #14 in Paul’s little series.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search