Skip to content
🛠️ToolsShed

EditorConfig Generator

Generate .editorconfig files for consistent coding styles across editors.

# EditorConfig — https://editorconfig.org
root = true

[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
max_line_length = 120

[*.json]
indent_size = 2

[*.md]
trim_trailing_whitespace = false

About this tool

EditorConfig is a configuration file format that helps development teams maintain consistent code formatting styles across different editors and IDEs. When team members use different editors—Visual Studio Code, JetBrains IDEs, Sublime Text, Vim, or others—an .editorconfig file ensures that indentation, line endings, charset, and other formatting rules remain uniform regardless of which tool each person prefers. This eliminates formatting conflicts in version control systems and reduces time spent on style discussions.

To use this generator, simply select your preferred settings for indentation type (tabs or spaces), indent size, line ending style (LF, CRLF, or auto-detect), and charset. You can also configure rules for specific file types like Python, JavaScript, JSON, or any other language you work with. Once you've customized all settings, download the generated .editorconfig file and place it in your project root directory. Your team members' editors will automatically apply these rules when they open files in that project.

EditorConfig integrates seamlessly with most modern editors through built-in support or lightweight plugins, making it one of the simplest ways to enforce code style consistency without additional build tools or linters. Teams working on open-source projects, corporate codebases, or collaborative environments benefit most, as it creates a single source of truth for formatting preferences. The tool is particularly useful for polyglot projects where multiple programming languages coexist, since .editorconfig rules can be tailored per file extension.

Frequently Asked Questions

Code Implementation

# Generate a .editorconfig file programmatically

def generate_editorconfig(indent_style="space", indent_size=2, end_of_line="lf",
                           charset="utf-8", trim_trailing_whitespace=True,
                           insert_final_newline=True) -> str:
    lines = [
        "# EditorConfig is awesome: https://editorconfig.org",
        "",
        "# top-most EditorConfig file",
        "root = true",
        "",
        "[*]",
        f"indent_style = {indent_style}",
        f"indent_size = {indent_size}",
        f"end_of_line = {end_of_line}",
        f"charset = {charset}",
        f"trim_trailing_whitespace = {str(trim_trailing_whitespace).lower()}",
        f"insert_final_newline = {str(insert_final_newline).lower()}",
        "",
        "[*.md]",
        "trim_trailing_whitespace = false",
        "",
        "[Makefile]",
        "indent_style = tab",
        "",
        "[*.{json,yml,yaml}]",
        "indent_size = 2",
    ]
    return "\n".join(lines)

config = generate_editorconfig(indent_style="space", indent_size=4)
print(config)

# Write to file
with open(".editorconfig", "w") as f:
    f.write(config)

Comments & Feedback

Comments are powered by Giscus. Sign in with GitHub to leave a comment.