We don’t allow questions seeking recommendations for software libraries, tutorials, tools, books, or other off-site resources. You can edit the question so it can be answered with facts and citations.
Closed 9 years ago.
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(7)
艺术风格。
http://astyle.sourceforge.net/
Artistic Style.
http://astyle.sourceforge.net/
我一直发现 Vim 的代码格式化程序是一个不错的选择。它支持多种语言并且可以进行合理的定制。
您可以像这样将相关命令输入到 vim 中:
说明:
gg=G
格式化文件:wq
保存文件并返回到命令提示符I've always found Vim's code formatter a great option. It is aware of many languages and can be reasonably customized.
You can pipe the relevant commands into vim like this:
Explanation:
gg=G
formats the file:wq
saves the file and returns to the command prompt如果您已将自动格式化选项设置为 Eclipse 中的项目特定设置,则可以执行以下操作:
这意味着您实际上为此目的安装和配置 Eclipse(如果只是为了使用它的自动格式化功能),无论您通常使用什么编辑器。 :)
来源: http:// blogs.operationaldynamics.com/andrew/software/java-gnome/eclipse-code-format-from-command-line
附加说明:
关于 Mac OS X 的
If you have set your auto-formatting options as project-specific settings in Eclipse, you can do something like:
This means that you practically install and configure Eclipse for this purpose if only for using it's autoformatting features, regardless of what editor you use normally. :)
Source: http://blogs.operationaldynamics.com/andrew/software/java-gnome/eclipse-code-format-from-command-line
Additional Notes
On Mac OS X:
查看
indent
和enscript
。Check out
indent
andenscript
.Vim 通常具有自动语法突出显示功能,并且在安装时可在大多数基于 Unix 的系统上使用。对于 Vim 中的格式化和缩进,我在启动时自动使用
:set autoindent
和:set tabstop=4
。autoindent
保留开始新行时的当前缩进,而tabstop
设置按 Tab 时代码的缩进量(仅适用于缩进,适用于 Tab in一般使用shiftwidth
)。要在启动 Vim 时配置这些选项,请将它们放在~/.vimrc
文件中。Vim generally has automatic syntax highlighting and is available on most Unix-based systems when you install. For formatting and indentation in Vim I use the
:set autoindent
and:set tabstop=4
automatically when I start it.autoindent
keeps the current indentation you are at when you start a new line, andtabstop
sets how much your code is indented when you press tab (only for indentation, for tab in general useshiftwidth
). To have these options configured whenever you start Vim put them in a~/.vimrc
file.对于 XML 和 HTML,我使用了 htb。
如果您是 Eclipse 用户,那么 JTidy 是另一个选择。
对于 Java,有 Jalopy。
For XML and HTML I have used htb.
If you are an Eclipse user then JTidy is another option.
For Java there is Jalopy.
因此,我提请您注意 Style Revisor,带有 GUI 和命令行界面的源代码格式化程序。它将支持不同的语言,包括 JavaScript 和 PHP。如果您对命令行使用感兴趣 - 您可以将自己的格式样式定义为插件。当然,您也可以使用许多预定义的样式。示例:
目前,Style Revisor 支持两种语言:C 和 Objective-C。欢迎:http://style-revisor.com/
真诚的。
So, I bring to your attention Style Revisor, source code formatter with GUI and command-line interface. It will be support different languages, include JavaScript and PHP. If you're interested in command-line usage - you can define your own formatting style as addon. Of course, you can also use many predefined styles. Example:
Currently, Style Revisor supports two languages: C and Objective-C. Welcome: http://style-revisor.com/
Sincerely.