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.
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
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.
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.
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.
To keep track of your location in the code easily with the breadcrumbs – small markers at the bottom of the editor that help you navigate around your code. CLion shows namespaces, classes, structures, functions, and lambdas there.
CLion allows you to select a predefined coding style to apply to your code style
configuration. There are Google, LLVM,
LLDB, GNU, Microsoft,
code styles available, as well as Allman,
Whitesmiths or K&R braces guidelines. Use
Set from... | Predefined
Style to select
This applies to code formatting options, C/C++ naming style, and header guards.
CLion respects the naming scheme you provide. The selected settings will be used when:
You can configure the style manually in Settings | Editor | Code Style | C/C++ | Naming Convention or select naming from the predefined scheme.
Thanks to parameter name hints, you can avoid switching to the function signature while exploring a function call. This in turn should help increase the code readability.
For function calls, lambdas, constructors, initializer lists, and macro expressions, CLion shows the names of the parameters for the passed arguments. This works if an argument is a literal or an expression with more than one operand.
CLion comes with ClangFormat as an alternative code formatter. Turn it on for your current project or all projects in CLion and let CLion use it to format your code.
CLion detects .clang-format config files in your project and will suggest switching to ClangFormat.
If you have customized your .clang-format config files in the project, you can benefit from code assistance when you update them.
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+/.
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.
To accurately and safely remove enclosing parts in complicated code with lots
statements, use Unwrap/Remove… action (Ctrl+Shift+Delete). It
suggests the options depending on where your caret is and is capable of unwrapping
for control statements.
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.
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.
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.
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.
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.