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.

Multiple selection allows you to put a cursor in multiple locations in your file and edit them at once. This feature works with all languages supported by AppCode such as Objective-C, C, C++, HTML, JavaScript, CSS and more.


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

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 (Cmd+X);
  • Move caret to next word (or with selection): Alt + -> (Alt + Shift + ->);
  • Move caret to previous word (or with selection): Alt + <- (Alt + Shift + <-);
  • Complete statement (Shift+Cmd+Enter);
  • Extend selection to the next logical block of code (Alt+Up);
  • Join lines (Ctrl+Shift+J);
  • 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- :
mc_occurrences

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 (Alt+Cmd+C) refactoring.

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

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

Read more tips’n’tricks posts in our blog.

This entry was posted in Tips'n'Tricks and tagged , . Bookmark the permalink.

One Response to Do several things at once with AppCode

  1. Konstantin says:

    We need code fold region !

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">