Do several things at once with AppCode
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
⌥⇧ 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):
- Move caret to line start (or with selection):
- Copy (
⌘C) / Paste (
⌘V) / Cut actions (
- Move caret to next word (or with selection):
- Move caret to previous word (or with selection):
- Complete statement (
- Extend/shrink 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
⌃G (to delete from the selection press
⇧⌃G) or select all occurrences at once by
⌃⌘G. For example, let us change all
NSString constants’ postfixes in a piece of code below from Pref to PrefKey :
In the example above we can’t achieve the same result with Rename (
⇧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 (
⇧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 (
⌥⌘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 (
⌥⇧⌘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
⌥⏎ 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.
Subscribe to Blog updates
Thanks, we've got you!
Writing Code Documentation in AppCode
Code documentation can save you a lot of time and headaches. On the other hand, it also takes a lot of effort to write and maintain it. In this article, we will look at the AppCode features that can help you create detailed and well-structured code documentation and keep it updated after code refact…
Polish Your Code with AppCode’s Inspections and Intentions
AppCode is constantly analyzing your code to find parts that can be improved. It provides sets of code inspections and intention actions for each supported language for this exact purpose. Inspections locate unused or redundant code, syntax errors, probable bugs, spelling mistakes, obsolete or redun…
Navigation in AppCode
Navigating through files and source code, especially in complex projects, can eat up a lot of time, which is why it is essential to learn how to move around quickly in your IDE. AppCode provides plenty of navigation features that can help you move faster. In this blog post, we’ll take a look at some…
Server-side Swift in AppCode
In this short article we’ll take a look at various AppCode features that are useful for server-side Swift development, as now you can open standalone SPM projects in AppCode on macOS. Check out and open the project On the Welcome screen, click the Get from VCS button and enter the address of the Fe…