Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I set IntelliJ to auto indent the code body?

Question 1: Can IntelliJ be set to indent the code body automatically upon making a new line?

Here is an example of what I mean:

I have this method:

    public static void main(String[] args)
        {
            System.out.println("Hi there.");
        }

Upon hitting the return key after typing the expression, I get this:

    public static void main(String[] args)
        {
            System.out.println("Hi there.");
        // the new line aligns itself with the braces.
        }

I would like it to do this:

    public static void main(String[] args)
        {
            System.out.println("Hi there.");
            // the new line aligns itself with the preceding line
        }

I haven't been able to locate an option anywhere under Settings that would make this the default behavior. Does it exist and am I missing it or am I looking for a unicorn?

Question 2: Is there an option to have the code body indented by default? If so, where can it be found?

Example:

Upon using the "Reformat Code..." command, I get this:

    public static void main(String[] args)
        {
        System.out.println("Hi there.");
        // the code body is realigned with the braces
        }

Is it possible to set IntelliJ to do this, and if so, where can I find that option?:

    public static void main(String[] args)
        {
            System.out.println("Hi there.");
            // the code body is indented from the braces
        }

That is another thing I cannot seem to find in the Settings options.

Any help would be great. Thanks for your time.

like image 423
nihilon Avatar asked Oct 05 '22 08:10

nihilon


1 Answers

You should use the Next line, each shifted option:

enter image description here

like image 199
maba Avatar answered Oct 10 '22 02:10

maba