How do I autoindent in Netbeans?

淺唱寂寞╮ 提交于 2019-11-26 18:48:30

问题


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.


回答1:


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




回答2:


Pressing Alt+Shift+F indents your selection. If nothing's selected, it indents the whole file.

In newer versions of NetBeans, 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 press Alt+Shift+F. NetBeans asks "Recursively format selected files and folders?" and pressing OK will recursively format all the selected files/folders.

On Mac OS X, shortcut is Ctrl+Shift+F. (note: it's Ctrl and not )

I've used above shortcuts on NetBeans 7 and 8.




回答3:


Shift + Alt + F indents the whole file.




回答4:


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




回答5:


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




回答6:


Here's the complete procedure to auto-indent a file with Netbeans 8.

First step is to go to Tools -> Options and click on Editor button and Formatting tab as it is shown on the following image.

When you have set your formatting options, click the Apply button and OK. Note that my example is with C++ language, but this also apply for Java as well.

The second step is to CTRL + A on the file where you want to apply your new formatting setting. Then, ALT + SHIFT + F or click on the menu Source -> Format.

Hope this will help.




回答7:


If you want auto-indent just like Emacs does it on TAB, i.e. indent the current line and move the cursor to the first non-whitespace character, do this:

  1. Go to Tools -> Options -> Editor -> Macros
  2. Create a new macro and call it something like "tabindent"
  3. Insert the following macro code:

    reindent-line caret-line-first-column caret-begin-line

  4. Click "Set Shortcut" and press TAB




回答8:


I have netbeans 6.9.1 open right now and ALT+SHIFT+F indents only the lines you have selected.

If no lines are selected then it will indent the whole document you are in.

1 possibly unintended behavior is that if you have selected ONLY 1 line, it must be selected completely, otherwise it does nothing. But you don't have to completely select the last line of a group nor the first.

I expected it to indent only one line by just selecting the first couple of chars but didn't work, yea i know i am lazy as hell...




回答9:


To format all the code in NetBeans, press Alt + Shift + F. If you want to indent lines, select the lines and press Alt + Shift + right arrow key, and to unindent, press Alt + Shift + left arrow key.




回答10:


for Java NetBeans 7.1 and later, even in NetBeans 8.0 (That i´m currently using) and later, the shortcut is:

Alt+Shift+F

if you look into the KeyMap accessing from the menu: Tools -> Options -> Keymap, the "action" is Format defined with the Shortcut : Alt+Shift+F



来源:https://stackoverflow.com/questions/1311912/how-do-i-autoindent-in-netbeans

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!