IntelliJ IDEA 2017.2 Help

Command Line Formatter


Command-line source code formatter is a special functionality within IntelliJ IDEA that lets you format arbitrary files outside of a project. So doing, the formatter makes use of XML files with the exported code style settings (Settings/Preferences | Editor | Code Style - Manage - Export Code Style XML File) and a file specification that defines a file or a group of files to be formatted.

For the files to be formatted there should be corresponding plugins which support the required file types. For example, PHP files will be formatted only if PHP plugin is installed.

Formatter launcher script

The script is format.bat/ (Windows/Linux,Mac) in <IntelliJ IDEA_HOME>/bin directory, where <IntelliJ IDEA_HOME> is IntelliJ IDEA's root installation directory. The script launches IntelliJ IDEA, which formats the specified files and quits. If launched without any parameters or with -h parameter, the script outputs a list of its options.


format [-h] [-r|-R] [-s|-settings settingsPath] [-m|-mask masks] [path1 [path2]...]


-hShows a help message and quits.
-r|-RScans directories specified in path1,path2... recursively.
-s|-settings settingsPathsettingsPath is a path to the file with the exported code style settings.

If this parameter is omitted, the default code style settings are used.

-m|-mask masksA comma-separated list of file masks, which define the files to be processed. The wildcard characters * (any string), ? (any single character) are supported.
pathNA path to a file or a directory to be processed.


1. Format all the files in C:\Data\src directory, including all subdirectories, using the default code style settings:

format -r C:\Data\src

2. Non-recursively format all .java and .html files in C:\Data\src directory, using code style settings from C:\Data\settings.xml:

format -s C:\Data\settings.xml -m * .java,*.html C:\Data\src
Last modified: 29 November 2017

See Also