How do I autoindent in Netbeans?
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.
Related videos on Youtube
Elazar Leibovich
Updated on July 22, 2020Comments
-
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 over 12 yearsAlt+Shift+F now reformats only a selection, not the whole file.
-
crowmagnumb almost 10 yearsYou 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 over 7 yearsI've protected this question as I see many thanks answer by low rep users on it.
-
-
Elazar Leibovich over 14 yearsStill 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 about 13 yearsThanks. 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 almost 11 yearsI 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 about 10 yearsCtrl+Shift+F opens the "Find in Projects" dialog box
-
arango_86 over 8 years"Ctrl + Shift + F" works for me in my Mac with "NetBeans IDE 8.0.2".
-
Marco Marsala about 8 yearsTried it with a minified file (all code on one line) and won't indent anything: the whole file stays on one line.
-
Mohammad Fareed almost 8 yearsLoL, 'ctrl' + 'shift' + 'f' is shortcut for Find in All Files
-
Max O. over 7 yearsThis comment shows up directly on google search, gz :D