Tips & Tricks

Get Typing Superpowers

CLion does its best to help you develop at the speed of thought. Code generation takes care of the repetitive tasks; code completion saves your time typing, while code navigation lets you move around the code instantly. Talking about quicker code writing, code generation (for getters/setters, constructors/destructors), generate definitions, implement and override functions and create from usage can make you significantly more productive.

The latest CLion EAP adds a new member to the family: Complete Statement.

Complete Statement helps you create syntactically correct code constructs by inserting the necessary syntax elements and getting you in position to start typing the next statement. CLion will insert parentheses, braces, semicolons, quotes, etc. for you as necessary so you avoid moving the caret manually.

To use Complete Statement, press Ctrl+Shift+Enter on Linux/Windows, or ⇧⌘⏎ on OS X.

Let’s take a closer look at some scenarios that now can be sped up. Are you ready for gifs? 🙂

Let’s start from the very beginning: creating a new namespace. Type the keyword (with the help of completion) and the name, and use Complete Statement to add the braces automatically:

Now that we have a namespace, let’s declare classes, structures, enums or enum classes. Again, there is no need to type ‘{ … };’ – Complete Statement will insert them for you:

Let’s move forward and declare some function and ask CLion to create a definition (Alt+Enter):

Now that we have a definition stub, we can fill it with some code. If you use Complete Statement, control statements like if, if ... else, for, while, do, switch will be completed with the missing braces, as will usual statements. The correct #include directive can be added with a quick-fix (Alt+Enter):

Notice how correct formatting is applied to the resulting code when Complete Statement is used.

While iterating, live templates can be handy to generate code:

However, if you still decide to type it by hand, to introduce some changes to this universal loop template, Complete Statement will again add all the necessary parentheses and braces and position the caret inside the loop, so that you can immediately start implementing the body.

What if there is more than one place to position the caret? Let’s check one more trick for getting a for loop quicker: press the Complete Statement shortcut several times and let the caret “travel” across the for loop so that you can fill the proper part:

If you need to get a function definition, don’t use the Complete Statement after you’ve written the function signature, since it will only add “;” at the end of the line. Complete Statement can’t guess it and so doesn’t add braces by default. Use generate definitions or ‘create from usage’, or a simple completion to get braces automatically and the caret positioned inside the function body, so that you can start implementing it immediately:

That’s it! Doesn’t it look handy?! Try it out for yourself and see how much faster your typing can get with CLion’s help.

Since Complete Statement functionality is rather new, there may be bugs (stable version is planned for CLion 2016.2). Please do share invalid cases with us so that we can fix them before the release. Check it right now. Thanks!

The CLion Team

Comments below can no longer be edited.

6 Responses to Get Typing Superpowers

  1. Avatar

    Alexander Münch says:

    May 18, 2016

    The “right now” link is wrong 😉 Seems to be two times behind one another.

    • Anastasia Kazakova

      Anastasia Kazakova says:

      May 18, 2016

      You are right) Thanks! Fixed.

  2. Avatar

    Roman says:

    May 18, 2016

    animation where user selects last ‘s’ for class from pop-up menu instead of typing it is an a sort of anti-example.

    • Anastasia Kazakova

      Anastasia Kazakova says:

      May 19, 2016

      Probably, you are right and the sample is not very good, since usually ‘class’ is on top and you can complete much earlier.

  3. Avatar

    NoName says:

    May 23, 2016

    Is there a chance that 2016.2 will give CPP-1727 some love too…? 🙂

    • Anastasia Kazakova

      Anastasia Kazakova says:

      May 24, 2016

      We’ll have them in the queue, but can’t be sure there will be resources to finish it for 2016.2.

Discover more