我如何在Netbeans中autoindent ?

时间:2022-10-30 14:44:42

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.

在eclipse中,您可以单击任意一行的Ctrl+I,它会根据您在设置中选择的缩进方案自动缩进行或行组。

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

我真的很怀念Netbeans的这个功能。有什么相同的特征吗?

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.

我知道Alt+Shift+F但还不够好。我想缩进一组行,而不是所有的文件。

10 个解决方案

#1


86  

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

打开工具->选项-> Keymap,然后查找名为“重新缩进当前行或选择”的动作,并设置任何你想要的快捷方式。

#2


162  

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

按Alt+Shift+F,缩进你的选区。如果没有选择,它会缩进整个文件。

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.

在新版本的NetBeans中,您甚至可以一次格式化多个文件/文件夹!在Projects窗口/侧栏中,如果您选择一个或多个文件夹或文件,并按Alt+Shift+F。NetBeans要求“递归地格式化选定的文件和文件夹?”然后按下OK将递归地格式化所有选定的文件/文件夹。

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

在Mac OS X上,快捷键是Ctrl+Shift+F。(注:按Ctrl,不是⌘)

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

我在NetBeans 7和8上使用了以上的快捷方式。

#3


20  

Shift + Alt + F indents the whole file.

Shift + Alt + F可以缩进整个文件。

#4


9  

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

选择要重新格式化的行(缩进),然后按Alt+Shift+F。只有选中的行才会被重新格式化。

#5


5  

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

Ctrl+Shift+F将在页面中执行所有代码的格式。

#6


4  

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:

如果你想要自动缩进,就像Emacs在标签上那样做,即缩进当前行并将光标移动到第一个非空格字符,这样做:

  1. Go to Tools -> Options -> Editor -> Macros
  2. 去工具->选项->编辑->宏。
  3. Create a new macro and call it something like "tabindent"
  4. 创建一个新的宏,并将其命名为“tabindent”
  5. Insert the following macro code:

    插入以下宏代码:

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

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

  6. Click "Set Shortcut" and press TAB

    点击“设置快捷方式”,按TAB键。

#7


4  

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

下面是使用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.

第一步是使用工具->选项,点击编辑按钮和格式标签,如下图所示。

我如何在Netbeans中autoindent ?

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.

设置格式选项后,单击Apply按钮,然后单击OK。注意,我的示例使用c++语言,但这也适用于Java。

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.

第二步是在要应用新的格式化设置的文件上按CTRL + A。然后,ALT + SHIFT + F或点击菜单源->格式。

Hope this will help.

希望这将帮助。

#8


2  

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

我现在已经打开了netbeans 6.9.1,而ALT+SHIFT+F只对你选中的行进行了修改。

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


2  

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.

要格式化所有的NetBeans的代码,按Alt + Shift + f。如果你想缩进行,选择行,按Alt + Shift +右箭头键,然后按住Alt + Shift +左箭头键。

#10


2  

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

对于Java NetBeans 7.1及以后,即使在NetBeans 8.0(目前我´使用)和后,快捷方式是:

Alt+Shift+F

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

如果你查看从菜单中访问的KeyMap: Tools ->选项-> KeyMap,“action”是用快捷方式定义的格式:Alt+Shift+F。

#1


86  

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

打开工具->选项-> Keymap,然后查找名为“重新缩进当前行或选择”的动作,并设置任何你想要的快捷方式。

#2


162  

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

按Alt+Shift+F,缩进你的选区。如果没有选择,它会缩进整个文件。

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.

在新版本的NetBeans中,您甚至可以一次格式化多个文件/文件夹!在Projects窗口/侧栏中,如果您选择一个或多个文件夹或文件,并按Alt+Shift+F。NetBeans要求“递归地格式化选定的文件和文件夹?”然后按下OK将递归地格式化所有选定的文件/文件夹。

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

在Mac OS X上,快捷键是Ctrl+Shift+F。(注:按Ctrl,不是⌘)

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

我在NetBeans 7和8上使用了以上的快捷方式。

#3


20  

Shift + Alt + F indents the whole file.

Shift + Alt + F可以缩进整个文件。

#4


9  

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

选择要重新格式化的行(缩进),然后按Alt+Shift+F。只有选中的行才会被重新格式化。

#5


5  

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

Ctrl+Shift+F将在页面中执行所有代码的格式。

#6


4  

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:

如果你想要自动缩进,就像Emacs在标签上那样做,即缩进当前行并将光标移动到第一个非空格字符,这样做:

  1. Go to Tools -> Options -> Editor -> Macros
  2. 去工具->选项->编辑->宏。
  3. Create a new macro and call it something like "tabindent"
  4. 创建一个新的宏,并将其命名为“tabindent”
  5. Insert the following macro code:

    插入以下宏代码:

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

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

  6. Click "Set Shortcut" and press TAB

    点击“设置快捷方式”,按TAB键。

#7


4  

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

下面是使用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.

第一步是使用工具->选项,点击编辑按钮和格式标签,如下图所示。

我如何在Netbeans中autoindent ?

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.

设置格式选项后,单击Apply按钮,然后单击OK。注意,我的示例使用c++语言,但这也适用于Java。

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.

第二步是在要应用新的格式化设置的文件上按CTRL + A。然后,ALT + SHIFT + F或点击菜单源->格式。

Hope this will help.

希望这将帮助。

#8


2  

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

我现在已经打开了netbeans 6.9.1,而ALT+SHIFT+F只对你选中的行进行了修改。

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


2  

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.

要格式化所有的NetBeans的代码,按Alt + Shift + f。如果你想缩进行,选择行,按Alt + Shift +右箭头键,然后按住Alt + Shift +左箭头键。

#10


2  

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

对于Java NetBeans 7.1及以后,即使在NetBeans 8.0(目前我´使用)和后,快捷方式是:

Alt+Shift+F

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

如果你查看从菜单中访问的KeyMap: Tools ->选项-> KeyMap,“action”是用快捷方式定义的格式:Alt+Shift+F。