Clion code formatting to align variables
Asked Answered
J

2

5

Is it possible to change the options in Clion so that the variables are aligned like so:

enter image description here

This should be applied in structs and methods.

Jaco answered 22/2, 2016 at 10:11 Comment(4)
Err... your variables are not aligned.Orthicon
@Orthicon yea that's a valid point, but you get the idea, let me try and get a better image in the meantimeJaco
Oh, you're talking about source code formatting not alignment in memory layout, right?Wed
@Wed yes absolutelyJaco
G
11

Yes.

Settings -> Editor -> Code Style -> C/C++ -> Wrapping and Braces -> Variable groups -> Align in columns

You can of course also use a custom formatting tool that does it as well.

Garrity answered 22/2, 2016 at 10:19 Comment(4)
Oh wow, thanks a lot, I didn't see that option being packed by 100 other options.Jaco
I am sorry, is this possible to align the comments on the "right" as well ? so that the comments are aligned too ? have you seen that option ?Jaco
Not sure if that is also possible. If not, you can also use an external tool for formatting, see: https://mcmap.net/q/347870/-using-clang-format-in-clion/620382Garrity
This setting behaves weirdly if you also change the space insert from before to after in * declarations. Apparently the * is still chosen as alignment character.Lacerta
D
0

after all tuning you can also use shortcuts "Ctrl+Alt+L" to make alignment

Define answered 14/12, 2022 at 13:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.