Since version 3 AppCode includes an awesome feature – multiple cursors and selections, that allows you to do many deals at a time increasing your productivity! Let’s see how you can use it and when it’s a good case for this feature.
To add/remove a caret press
Alt+Shift and select the caret locations with the mouse. To restore single caret mode, use
Esc. Now you can write code simultaneously in all these positions. And a good news for you – autocompletion and live templates will work in this case. For example, let us add some logging to the code with log live template:
Actually a lot of editing actions are working perfectly in a multiple case, for example:
- Move caret to line end (or with selection):
Cmd + ->(
Shift + Cmd + ->);
- Move caret to line start (or with selection):
Cmd + <-(
Shift + Cmd + <-);
- Copy (
Cmd+C) / Paste (
Cmd+V) / Cut actions (
- Move caret to next word (or with selection):
Alt + ->(
Alt + Shift + ->);
- Move caret to previous word (or with selection):
Alt + <-(
Alt + Shift + <-);
- Complete statement (
- Extend selection to the next logical block of code (
- Join lines (
- and much more.
Autocompletion and live templates are also available, as we said before. The context is determined from the location of the last set cursor, resulting changes are applied to all cursors.
You can also easily change any repeating code fragments at once with placing cursor at any occurrence and then adding next occurrence of the current word to the selection by pressing
Ctrl+G (to delete from the selection press
Shift+Ctrl+G) or select all occurrences at once by
Ctrl+Cmd+G. For example, let us change all NSString literals’ prefixes in a piece of code below from Title- to MainTitle- :
In the example above we can’t achieve the same result with Rename (
Shift+F6) refactoring. However there are situations when Refactoring actions are more appropriate than using multiple cursors. For example, if you are renaming variable occurrences we advise you to use Rename (
Shift+F6) refactoring because of two reasons:
- not to break any usage you could miss while placing the cursor;
- not to rename the usage from another scope by accident.
AppCode takes care of these situations so that you can rename safely with it.
Following the same reasons for the case when there are several equal NSString literals in a block of code, instead of using multiple cursors for changing the values try to use:
- Extract Variable (
Alt+Cmd+V) refactoring or
- Extract Constant (
That will keep your code neat and safe.
We’d like to emphasize here that inspections and quick-fixes functionality are not available with multiple cursors. The reason here is that for applying quick-fixes in several places at once AppCode has a convenient batch-mode. Just call inspection by its name (
Alt+Shift+Cmd+I) or use Code | Inspect Code for a desired scope, select a group of problems you’d like to fix in the resulted window and press
Alt+Enter to apply fixes:
We encourage you to try AppCode 3 and the awesome multiple cursors feature if you haven’t already, and do give us your feedback to help make it even more intelligent. To sum up let us show you one fantastic sample with multiple cursors:
Read more tips’n’tricks posts in our blog.