Ian Boyd
Ian Boyd

Reputation: 256661

How to disable auto-indenting in NetBeans IDE 14?

Short Version

How do i disable automatic indenting when i press Enter in NetBeans IDE?

Long Version

Consider some code, with my insertion caret at the end of the last line:

byte[] data;
try {
data = Base64.getDecoder().decode(s);

When i press Enter, it's because i want to insert a carriage return, and move the caret to the start of the next line:

byte[] data;
try {
data = Base64.getDecoder().decode(s);Enter

Except what happens in NetBeans, is that also automatically indents for me:

byte[] data;
try {
data = Base64.getDecoder().decode(s);Enter
Tab

How do i turn this off?

Research Effort

Upvotes: 1

Views: 498

Answers (1)

skomisa
skomisa

Reputation: 17353

It is straightforward to turn off automatic indentation in NetBeans 14, but the process is not intuitive for Java source. These settings must be applied in sequence after navigating to the Tools > Options > Editor > Formatting screen:

  • Select Language: All Languages and Category: Tabs and Indents, and then uncheck the checkbox Enable Indentation and click the Apply button. This will turn off automatic indentation for all languages by default, but that global setting might still be overridden for individual languages.

  • Select Language: Java and Category: Tabs and Indents, and then uncheck the checkboxes Use all Languages Settings and Enable Indentation, and click the OK button.

After making those changes the modified fields should look like this if you revisit the Tools > Options > Editor > Formatting screen:

  • Language: All Languages

    All Languages screen

  • Language: Java

    Java screen

Then, using your sample code, if the cursor is positioned at the end of the line containing data = Base64.getDecoder().decode(s); and Enter is pressed:

  • A new line will be inserted.
  • The cursor will be positioned at the start of that new line.

This is the sample code I used:

package javaantapplication1;

import java.util.Base64;

public class JavaAntApplication1 {

    private static byte[] s;

    public static void main(String[] args) {
        
    byte[] data;

    try { 
        data = Base64.getDecoder().decode(s);
        
    } 
}

Notes:

  • The steps to re-enable automatic indentation are not the reverse of those described above. Instead, simply revisit the first screen shown above, check Enable Indentation, and click OK. That is sufficient to enable indentation for Java again.
  • I don't think it is possible to have automatic indentation disabled only for Java source.
  • While better than nothing, the GUI for configuring indentation in NetBeans is confusing and inflexible.

Upvotes: 2

Related Questions