CLion integrates with the Prettier code formatter. You can reformat selected code fragments as well as entire files or directories using the Reformat with Prettier action. CLion adds this action as soon as you install Prettier as a dependency in your project or globally on your machine, Prettier is available in
Moreover, the key code style rules from the Prettier's configuration are applied to the CLion Code Style settings. As a result, generated code (e.g. after refactoring or quick-fix) and the code that is already processed with Prettier are formatted consistently.
Before you start
To install Prettier
Open the embedded Terminal ( or Alt+F12).
At the command prompt, type
npm install --save-dev --save-exact prettieror
npm install --global prettier. Learn more about installation modes from the Prettier Official website.
To configure Prettier in CLion
- On the Prettier page, that opens, specify the path to the
prettierpackage and choose the Node.js interpreter to use. If you choose the
Projectalias, CLion will automatically use the project default interpreter from the Node interpreter field on the Node.js and NPM page.
In most cases, CLion detects the project default interpreter and fills in the field itself. You can also choose another configured local interpreter or click and configure a new one.
To reformat code with Prettier
Select the code fragment to reformat in the editor or select a file or a folder in the Project tool window and press N/A or choose Reformat with Prettier on the context menu of the selection.
Alternatively, press Ctrl+Shift+A and click Reformat with Prettier in the Find Action pop-up list: