A cursor is a visual indicator showing where we’re editing code. Typically, only one cursor is used at a time. Multi-cursor editing is a feature that allows placing multiple cursors in the code simultaneously to edit in multiple locations at once. This can be particularly helpful for making bulk changes across similar lines of code.
There are several ways to enable multi-cursor editing in Xcode. To add a cursor with a single click, hold Control and Shift, then click where you want an additional cursor. Alternatively, if you want to add multiple cursors in the same column, hold Control, use the arrow keys to navigate up or down, and press Shift to add more cursors. You can also hold Option and drag the cursor to add several at once, and Control + Shift + click on any added cursor to remove it. Exiting multi-cursor mode can be done by pressing Esc.
Multi-cursor editing is beneficial when you need to perform repetitive edits, such as creating custom CodingKeys for a struct’s properties. For instance, after copying and pasting the properties of a struct into an enum, multi-cursor editing can be used to change each let keyword to case and remove property types, streamlining the setup of CodingKeys.
Another useful application of multi-cursor editing is adjusting method parameter indentation. By adding cursors before each parameter using Control + Shift + click, you can quickly insert line breaks to format each parameter onto a new line, making the method parameters more readable in multi-line format.