INI formatter — tidy sections, keys and spacing in .ini and .cfg files

Paste an INI, CFG or similar settings file and get clean section headers, consistent spacing around equals signs and one blank line between sections, with every comment kept.

Live demo · real result from this tool

Formatted INI

; app settings[server]host = 0.0.0.0port = 8080 [database]user = app# secret goes in envname = prod_db 

Processed on your device — nothing is uploaded.

How to use the INI formatter

  1. Paste your file into the Input box. The sample has untidy spacing, a padded [ server ] header and several blank lines.
  2. Tick or untick the options: Spaces around = (on by default), Align = within each section and Sort keys within sections.
  3. Copy the Formatted INI or download it as settings.ini.

What it does and when to use it

INI files are edited by hand over years, so they collect mixed key=value and key = value spacing, stray blank lines and headers like [ database ]. This tool gives the whole file one style. Aligned values are easier to scan in long sections, and sorted keys make it simple to compare two server configs line by line in the code diff viewer.

Similar clean-ups exist for other config formats: the Java properties formatter for .properties files, the env file sorter for .env files, and the TOML formatter for TOML.

How it works

The formatter does not use a parser library; it reads your text line by line:

  • Blank lines are dropped, then one blank line is put back before each section.
  • A line in square brackets starts a section, and the spaces inside the brackets are trimmed.
  • A line starting with ; or # is a comment and is held until the next key or section, so it moves with that line.
  • Any other line with = or : is split into key and value at the first separator. Lines with neither, such as skip-name-resolve, are kept unchanged.

With Align on, each key is padded to the longest key in its section. It all runs in your browser.

Worked examples

These are the tool’s own outputs.

The sample. [ server ] becomes [server], port =8080 and user= app become port = 8080 and user = app, the three blank lines shrink to one, and the # secret goes in env comment stays above name = prod_db.

Aligned git config.

[core]
editor       = vim
autocrlf     = input
excludesfile = ~/.gitignore ; global

The input had autocrlf : input, now an equals sign. The ; global note after the value is part of the value and is kept.

Sorted MySQL options, no spaces. With Sort keys on and Spaces around = off, the [mysqld] keys come out as bind-address, then the ; keep small comment with max_connections=50, then port=3306 and skip-name-resolve.

Limits and tips

  • Your own blank lines inside a section are removed. Use comments to group keys instead.
  • Multi-line values written with a backslash or extra indentation are treated as separate lines.
  • Duplicate keys are not reported. Watch for them when sorting brings them together.

Frequently asked questions

Are comments kept?
Yes. Lines starting with ; or # are kept, and each comment stays attached to the key, section or line just below it, even when you sort keys.
What happens to a colon separator?
A key written with a colon, such as autocrlf followed by a colon and input, is rewritten with an equals sign. Most INI readers accept both, but check yours if it only understands colons.
Does it sort sections as well as keys?
No. Sort keys within sections orders keys A to Z inside each section, ignoring case, but sections stay in the order you wrote them. A key that appears before the first section stays at the top.
Will it change my values?
No. Everything after the equals sign is copied as written, including quotes and any text after a semicolon on the same line. Only spaces around the separator and around section names change.
Which files can I use it for?
Any key=value file with [sections], such as php.ini, my.cnf, .gitconfig, desktop entries, setup.cfg, tox.ini and many game or app settings files. For TOML, which looks similar but has stricter rules, use the TOML formatter.

Written by the ToolsRift team · Last updated

Pages are drafted with AI assistance and checked by automated tests. How we write and check pages.

Was this tool useful?

Report a problem

Start typing to search every tool.

↑ ↓ to moveEnter to openEsc to close