How do I autoindent in Netbeans?

295,250

Solution 1

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

Solution 2

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 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.

Share:
295,250

Related videos on Youtube

Elazar Leibovich
Author by

Elazar Leibovich

Updated on July 22, 2020

Comments

  • Elazar Leibovich
    Elazar Leibovich almost 4 years

    In eclipse you can click Ctrl+I at any line, and it'll automatically indent the line or group of lines according to the indentation scheme you chose in the settings.

    I'm really missing this feature in Netbeans. Is there any equivalent feature?

    I'm aware of Alt+Shift+F but it's not good enough. I want to indent a group of lines, and not all the file.

    • Josef Sábl
      Josef Sábl over 12 years
      Alt+Shift+F now reformats only a selection, not the whole file.
    • crowmagnumb
      crowmagnumb almost 10 years
      You can also set your key mappings to be the same as Eclipse with one setting in the Preferences. I do this when I'm using NetBeans because I'm primarily an Eclipse user. That way I don't have to remember two systems.
    • Tushar
      Tushar over 7 years
      I've protected this question as I see many thanks answer by low rep users on it.
  • Elazar Leibovich
    Elazar Leibovich over 14 years
    Still doesn't work with JavaFX, but eclipse JavaFX plugin have this defect as well, so I guess I just have to wait for JavaFX to mature. Thanks!
  • Elazar Leibovich
    Elazar Leibovich about 13 years
    Thanks. Maybe it was fixed since I've written it, maybe I didn't notice and it was always OK. Good to know it's working (almost) as it should now.
  • kwah
    kwah almost 11 years
    I am a little late to the party but this shortcut does a lot more than just affect indentation. Out of the box, reformatting adds/removes linebreaks (for example on /** **/ comments and near curly brackets {}). This is particularly troublesome when working with other people's code and all you want to do is have the indentation match what you find readable.
  • Manu Manjunath
    Manu Manjunath about 10 years
    Ctrl+Shift+F opens the "Find in Projects" dialog box
  • arango_86
    arango_86 over 8 years
    "Ctrl + Shift + F" works for me in my Mac with "NetBeans IDE 8.0.2".
  • Marco Marsala
    Marco Marsala about 8 years
    Tried it with a minified file (all code on one line) and won't indent anything: the whole file stays on one line.
  • Mohammad Fareed
    Mohammad Fareed almost 8 years
    LoL, 'ctrl' + 'shift' + 'f' is shortcut for Find in All Files
  • Max O.
    Max O. over 7 years
    This comment shows up directly on google search, gz :D