Smart editor

Code completion

With CLion you can code faster by making use of Code Completion. Start typing the name of a keyword, variable, function or class to get a list of matching suggestions. To save even more time, enter just the uppercase characters of a name (CamelHumps matching) or even any part of it (Middle matching).

The IDE can also suggest completion options for symbols from external libraries and frameworks used in your project.

This basic code completion works as you type. In addition, CLion can provide smart completion (if you press Ctrl+Shift+Space) by intelligently filtering the suggestions based on the code context:

Code style

CLion keeps your code well formatted and compliant with the configured coding style guidelines. It works as you type, and also apply it explicitly with the Reformat Code action (press Ctrl+Alt+L).

Code style is configurable in Editor | Code Style settings. You can set up the general configuration, as well as language-specific options (for example, C/C++, CMake, HTML or XML).

Code style covers things like spaces, aligning rules, tabs and indents, code generation, and blank lines. For code style settings that affect code, CLion gives you an immediate preview, highlighting the line affected by the most recent change:

Advanced options

You can also choose to pick up and keep some of the existing formatting in specific files. When you open a file, CLion will tell you if its indents are different from your active code style settings.

You can then choose either to enforce your style settings or keep the existing indents as you edit the file, including any reformatting. This feature can be switched on/off in Editor | Code Style.. settings

CLion allows you to change settings applicable to the selected piece of code only. Select the code and use quick-fix (Alt+Enter) called Adjust code style settings:

Highlighting and configurations

Resolve context

In case the code highlighting depends on flags and variables coming from a CMake target, CLion is able to highlight the code in a proper way - just select a build/run configuration and the IDE automatically switches the resolve context for you.

If you still prefer the manual switcher, it's located in the bottom right corner of the editor.

Predefined code styles

CLion allows you to select a predefined coding style to apply to your code style configuration. There are Google, LLVM, LLDB, GNU, Qt and Stroustrup code styles available, as well as Allman, Whitesmiths or K&R braces guidelines. Use Set from... | Predefined Style to select your favourite.

Code selection and comments

To select a block of code quickly in CLion you can place a cursor inside the block and press Ctrl+W as many times as you need to expand selection, from a symbol to an expression, to a line, to a logical block of code, and so on. To shrink the selection to a smaller logical part, press Ctrl+Shift+W as many times as needed:

After selecting a block, you can apply a block comment (Ctrl+Shift+/) or line comment (Ctrl+/) to it. And if you’d like to comment a single line, you don’t even need to have the line selected — just have the caret on it and press Ctrl+/.

Parameter info

When you’re not sure what parameters a function accepts, CLion is there to help. Bring up Parameter Info (Ctrl+P) to see all available function signatures and parameters. When you start editing parameters, CLion greys out any incompatible signatures:

Multiple carets and selections

If you’ve ever dreamed about doing many things at a time, CLion can make your dream come true. With multiple carets, you can edit several locations in your file at the same time.

Select several locations to edit with the mouse (press Alt+Shiftand place a caret with mouse click) or simply add a couple of next occurrences to the selection with Alt+J (or remove them with Alt+Shift+J)

Then you’ll be able to edit all the selected places at the same time, benefitting from code completion and live templates, etc. in all these locations. When you’re done, press Esc to go back to single-caret mode.

Code reordering

You can move whole lines and blocks of code up/down to reorder code. To move a single line without even selecting it, simply press Alt+Shift+Up/Down. To move a selected block of code, use Ctrl+Shift+Up/Down.

Automatic imports

When you start using a symbol that is not yet imported, CLion will search and suggest adding the corresponding include, or even add it automatically when you complete code.

Quick definition

You can also see the implementation or declaration of a function without leaving your current context. Simply place the caret on a symbol and press Ctrl+Shift+I to bring up the Quick Definition popup:

Quick documentation

There is also the Quick Documentation popup (available via Ctrl+Q), which provides documentation for the selected class, function, variable, parameter, or macro.

Quick Documentation is able to show the macro substitution and inferred type for variables declared as auto, as well as links to the referenced types and Doxygen-styled documentation preview.