On this page
Editorconfig
EditorConfig
EditorConfig helps maintain consistent coding styles across different editors and IDEs. Most modern editors support EditorConfig natively or via plugins.
Documentation: https://editorconfig.org
Supported editors:
- VS Code (built-in)
- PyCharm/IntelliJ (built-in)
- Sublime Text (plugin required)
- Atom (plugin required)
- Vim (plugin required)
Installation:
- Copy this file to your project root as .editorconfig
- Ensure your editor has EditorConfig support enabled
- No additional configuration needed
# ==============================================================================
# ROOT
# ==============================================================================
# This is the top-most EditorConfig file
root = true
# ==============================================================================
# ALL FILES
# ==============================================================================
[*]
# Character set
charset = utf-8
# Line endings (use Unix-style on all platforms)
end_of_line = lf
# Ensure file ends with a newline
insert_final_newline = true
# Remove trailing whitespace
trim_trailing_whitespace = true
# ==============================================================================
# PYTHON FILES
# ==============================================================================
[*.py]
# Indentation
indent_style = space
indent_size = 4
# Line length (matches Black formatter)
max_line_length = 88
# ==============================================================================
# JAVASCRIPT/TYPESCRIPT FILES
# ==============================================================================
[*.{js,jsx,ts,tsx}]
# Indentation
indent_style = space
indent_size = 2
# Line length (matches Prettier)
max_line_length = 100
# Quote style
quote_type = single
# ==============================================================================
# JSON FILES
# ==============================================================================
[*.json]
# Indentation
indent_style = space
indent_size = 2
# ==============================================================================
# YAML FILES
# ==============================================================================
[*.{yml,yaml}]
# Indentation
indent_style = space
indent_size = 2
# ==============================================================================
# MARKDOWN FILES
# ==============================================================================
[*.md]
# Indentation
indent_style = space
indent_size = 2
# Don't trim trailing whitespace (two spaces = line break in Markdown)
trim_trailing_whitespace = false
# Line length (Markdown can be longer)
max_line_length = 120
# ==============================================================================
# HTML/CSS FILES
# ==============================================================================
[*.{html,css,scss,sass,less}]
# Indentation
indent_style = space
indent_size = 2
# ==============================================================================
# CONFIGURATION FILES
# ==============================================================================
[*.{toml,ini,cfg}]
# Indentation
indent_style = space
indent_size = 4
# ==============================================================================
# SHELL SCRIPTS
# ==============================================================================
[*.{sh,bash,zsh}]
# Indentation
indent_style = space
indent_size = 2
# ==============================================================================
# SQL FILES
# ==============================================================================
[*.sql]
# Indentation
indent_style = space
indent_size = 2
# Line length
max_line_length = 120
# ==============================================================================
# DOCKER FILES
# ==============================================================================
[Dockerfile*]
# Indentation
indent_style = space
indent_size = 2
[docker-compose*.yml]
# Indentation
indent_style = space
indent_size = 2
# ==============================================================================
# MAKEFILE
# ==============================================================================
[Makefile]
# Makefiles require tabs
indent_style = tab
indent_size = 4
[*.mk]
indent_style = tab
indent_size = 4
# ==============================================================================
# PACKAGE MANAGER FILES
# ==============================================================================
# package.json, package-lock.json
[package*.json]
indent_style = space
indent_size = 2
# requirements.txt, constraints.txt
[*requirements*.txt]
indent_style = space
indent_size = 4
# poetry.lock, Pipfile
[{Pipfile,poetry.lock}]
indent_style = space
indent_size = 4
# ==============================================================================
# GIT FILES
# ==============================================================================
[.gitignore]
indent_style = space
indent_size = 2
[.gitattributes]
indent_style = space
indent_size = 2
# ==============================================================================
# CI/CD FILES
# ==============================================================================
[.github/workflows/*.{yml,yaml}]
indent_style = space
indent_size = 2
[.gitlab-ci.yml]
indent_style = space
indent_size = 2
# ==============================================================================
# USAGE NOTES
# ==============================================================================
#
# This file automatically configures your editor to use the correct
# indentation and formatting settings for each file type.
#
# No manual configuration needed - just ensure EditorConfig is enabled
# in your editor.
#
# Common settings:
# - indent_style: "space" or "tab"
# - indent_size: Number of spaces (or tab width)
# - end_of_line: "lf" (Unix), "crlf" (Windows), "cr" (Mac)
# - charset: "utf-8", "latin1", etc.
# - trim_trailing_whitespace: true/false
# - insert_final_newline: true/false
# - max_line_length: Number (hint for editor, not enforced)
#
# EditorConfig vs Linters:
# - EditorConfig: Configures editor behaviour as you type
# - Linters (flake8, eslint): Enforce rules and catch errors
# - Formatters (black, prettier): Automatically format code
#
# All three work together:
# 1. EditorConfig sets up editor
# 2. You write code
# 3. Formatter auto-formats on save
# 4. Linter checks for errors
# 5. Pre-commit hooks enforce before commit
#
# Checking if EditorConfig is working:
# 1. Open a .py file
# 2. Press Tab
# 3. Should insert 4 spaces (not tab character)
# 4. Open a .js file
# 5. Press Tab
# 6. Should insert 2 spaces
#
# Troubleshooting:
# - Not working? Check if EditorConfig is enabled in your editor
# - VS Code: Should work by default
# - PyCharm: Settings → Editor → Code Style → Enable EditorConfig
# - Other editors: Install EditorConfig plugin
#
# More information: https://editorconfig.org