Is there a command-line Unix tool that will format/indent/prettify source code in different languages? I'm especially interested in Java, JavaScript, PHP, and XML, but ideally it would handle others.
(I'm not looking for something to generate syntax-highlighting markup; I already know of a few tools that do that.)
Open the required file. Go to Source | Format Document or press Ctrl+Shift+F.
The code formatting is available in Visual Studio Code (VSCode) through the following shortcuts or key combinations: On Windows Shift + Alt + F. On macOS Shift + Option + F. On Linux Ctrl + Shift + I.
Artistic Style. http://astyle.sourceforge.net/
If you have set your auto-formatting options as project-specific settings in Eclipse, you can do something like:
/opt/local/eclipse/eclipse -nosplash
-application org.eclipse.jdt.core.JavaCodeFormatter
-verbose
-config .settings/org.eclipse.jdt.core.prefs
src/ tests/ doc/examples/
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
On Mac OS X:
/Applications/eclipse/java-oxygen/Eclipse.app/Contents/MacOS/eclipse -nosplash -application org.eclipse.jdt.core.JavaCodeFormatter -verbose -config ~/my-eclipse-workspace/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.jdt.core.prefs MyClass.java
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:
vim MyClass.java <<< gg=G:wq
Explanation:
gg=G
formats the file:wq
saves the file and returns to the command promptCheck out indent
and enscript
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With