如何在 Netbeans 中自动缩进?
在 Eclipse 中,您可以在任意行单击 Ctrl+I,它会根据您在设置中选择的缩进方案自动缩进该行或一组行。
我真的很怀念 Netbeans 中的这个功能。有同等功能吗?
我知道 Alt+Shift+F 但它还不够好。我想缩进一组行,而不是整个文件。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(10)
快捷方式:
使用上述快捷方式时,NetBeans 会缩进您的选择。如果未选择任何内容,则会缩进整个文件。
您甚至可以一次格式化多个文件/文件夹!在
Projects
窗口/侧边栏中,如果您选择一个或多个文件夹或文件并使用快捷方式,NetBeans 会询问“递归格式化选定的文件和文件夹?”。按“确定”将递归格式化所有选定的文件/文件夹。以上快捷方式适用于版本 7 到 12 的 NetBeans。
Shortcut:
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.
打开工具 -> 选项 -> 键盘映射,然后查找名为“重新缩进当前行或选择”的操作并设置您想要的任何快捷键。
Open Tools -> Options -> Keymap, then look for the action called "Re-indent current line or selection" and set whatever shortcut you want.
Shift
+Alt
+F
缩进整个文件。Shift
+Alt
+F
indents the whole file.选择要重新格式化(缩进)的行,然后按 Alt+Shift+F。仅选定的行将被重新格式化。
Select the lines you want to reformat (indenting), then hit Alt+Shift+F. Only the selected lines will be reformatted.
Ctrl
+Shift
+F
将对页面中的所有代码进行格式化。Ctrl
+Shift
+F
will do a format of all the code in the page.以下是使用 Netbeans 8 自动缩进文件的完整过程。
第一步是转到“工具”->“工具”。选项,然后单击编辑器按钮和格式选项卡,如下图所示。
设置格式选项后,单击“应用”按钮并单击“确定”。请注意,我的示例使用的是 C++ 语言,但这也适用于 Java。
第二步是在要应用新格式设置的文件上按 CTRL + A。然后,ALT + SHIFT + F或点击菜单
Source ->格式
。希望这会有所帮助。
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.
要格式化 NetBeans 中的所有代码,请按 Alt + Shift + F。如果要缩进行,请选择行并按 Alt + Shift + 向右箭头键,要取消缩进,请按 Alt + Shift + 向左箭头键。
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.
如果你想像 Emacs 在 TAB 上那样自动缩进,即缩进当前行并将光标移动到第一个非空白字符,请执行以下操作:
插入以下宏代码:
重新缩进线
插入符行第一列
caret-begin-line
单击“设置快捷方式”并按 TAB
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:
Insert the following macro code:
reindent-line
caret-line-first-column
caret-begin-line
Click "Set Shortcut" and press TAB
我现在打开了 netbeans 6.9.1,并且 ALT+SHIFT+F 仅缩进您选择的行。
如果没有选择任何行,那么它将缩进您所在的整个文档。
一种可能的意外行为是,如果您仅选择了 1 行,则必须完全选择它,否则它不会执行任何操作。但您不必完全选择组的最后一行或第一行。
我希望它只通过选择前几个字符来缩进一行,但没有成功,是的,我知道我很懒......
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...
对于 Java NetBeans 7.1 及更高版本,甚至在 NetBeans 8.0(我当前使用的)及更高版本中,快捷方式为:
Alt+Shift+F
如果您查看从菜单访问的
KeyMap
:Tools
->选项
->键盘映射
,“操作”是用快捷键定义的格式:Alt+Shift+F< /kbd>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