Using clang-format in CLion

后端 未结 4 2043
天命终不由人
天命终不由人 2020-12-29 01:46

I\'d like to format my code using clang-format in CLion. I\'ve gone through the settings and haven\'t found any setting that would allow me to run an external command to tra

4条回答
  •  执念已碎
    2020-12-29 02:04

    You can use External Tools in CLion.

    Go to File->Settings->Tools->External Tools and click on the plus sign.

    A window should pop up. Use a name of your choice.

    For the Tool settings tab I'm using this configuration:

    • Program: clang-format-3.7 (you should use the name of your executable here)

    • Parameters: -i $FileName$

    • Working directory: $FileDir$

    Now, with your file open, you can go to Tools->External tools and run the config above. It basically calls clang-format and does inplace formatting.

    You can also set a custom keymap to it, just search the name of your external tool in "Keymap" of the Settings menu.

提交回复
热议问题