How do I autoindent in Netbeans?

Solution 1:

Shortcut:

  • Windows: Alt+Shift+F
  • Mac OS X: Ctrl+Shift+F (note: it's Ctrl and not )

On using above shortcut, NetBeans indents your selection. If nothing's selected, it indents the whole file.

You can even format multiple files/folders at a time! In the Projects window/sidebar, if you select one or more folders or files and use the shortcut, NetBeans asks "Recursively format selected files and folders?". Pressing OK will recursively format all the selected files/folders.

Above shortcuts works on NetBeans from versions 7 to 12.

Solution 2:

Open Tools -> Options -> Keymap, then look for the action called "Re-indent current line or selection" and set whatever shortcut you want.

Solution 3:

Shift + Alt + F indents the whole file.

Solution 4:

Select the lines you want to reformat (indenting), then hit Alt+Shift+F. Only the selected lines will be reformatted.

Solution 5:

Ctrl+Shift+F will do a format of all the code in the page.