Comprehensive, production-ready EditorConfig file for maintaining consistent coding styles across different editors and IDEs.
Download the .editorconfig file and place it in your project root:
curl -o .editorconfig https://raw.githubusercontent.com/gfmio/editorconfig/main/.editorconfig# Clone the repository
git clone https://github.com/gfmio/editorconfig.git
# Copy to your project
cp editorconfig/.editorconfig /path/to/your/project/# Add as a submodule
git submodule add https://github.com/gfmio/editorconfig.git .editorconfig-source
# Create a symlink (Unix/macOS/Linux)
ln -s .editorconfig-source/.editorconfig .editorconfig
# Or on Windows (requires admin)
mklink .editorconfig .editorconfig-source\.editorconfigEditorConfig helps maintain consistent coding styles across different editors and IDEs. When you open a file, your editor automatically applies the formatting rules defined in .editorconfig - no per-developer configuration needed.
Supports:
- Indentation style (spaces vs tabs)
- Indentation size
- Line endings (LF, CRLF)
- Character encoding
- Trailing whitespace
- Final newlines
- Maximum line length
This configuration covers 50+ programming languages and over 75 languages and file types (including markup, config, and data files), with conventions based on official style guides and community best practices.
Web Development:
- JavaScript (
.js,.jsx,.mjs,.cjs) - 2 spaces - TypeScript (
.ts,.tsx,.mts,.cts) - 2 spaces, single quotes - HTML, XML, SVG, Vue - 2 spaces
- CSS, SCSS, Sass, Less, Stylus - 2 spaces
Backend Languages:
- Python (
.py,.pyw,.pyx) - 4 spaces, 88 char max (Black compatible) - Go (
.go) - tabs (required bygo fmt) - Ruby (
.rb,.rake, Gemfile) - 2 spaces - PHP (
.php,.phtml) - 4 spaces - Java (
.java) - 4 spaces - C# (
.cs) - 4 spaces - Rust (
.rs) - 4 spaces, 100 char max - C/C++ (
.c,.cpp,.h,.hpp) - 4 spaces
Functional & Modern:
- Haskell, Elm, Scala, Clojure
- Elixir, Erlang, OCaml, F#
- Dart, Kotlin, Swift
- Crystal, Nim, Zig
Scientific & Data:
- R, Julia, MATLAB
- SAS, SPSS, Stata
- Jupyter Notebooks
Systems & Specialized:
- Assembly, WebAssembly
- CUDA, OpenCL, GLSL/HLSL
- Solidity, Vyper
- Fortran, COBOL, Pascal
- Lua, Perl, Groovy
Package Managers:
package.json,package-lock.json- no final newlineyarn.lock,pnpm-lock.yaml- proper handlingGemfile,Gemfile.lockbunfig.toml
Data Formats:
- JSON, JSONC, JSON5 - 2 spaces, no final newline
- YAML - 2 spaces (tabs would break YAML)
- TOML - 2 spaces
- XML - 2 spaces
- INI, Properties, Config files - 2 spaces
- CSV, TSV - preserves trailing whitespace
Documentation:
- Markdown (
.md) - 2 spaces, 80 char max, preserves trailing whitespace (for double-space line breaks) - reStructuredText (
.rst) - 3 spaces (RST convention) - AsciiDoc (
.adoc) - 2 spaces - LaTeX (
.tex) - 2 spaces
Containers & Orchestration:
- Docker (
Dockerfile,Dockerfile.*) - 2 spaces - Docker Compose (
docker-compose.yml) - 2 spaces - Kubernetes (
*.k8s.yml) - 2 spaces
Infrastructure as Code:
- Terraform (
.tf,.tfvars,.hcl) - 2 spaces - Vagrant (
Vagrantfile) - 2 spaces
CI/CD:
- GitHub Actions (
.github/workflows/*.yml) - 2 spaces - CircleCI (
.circleci/config.yml) - 2 spaces - Travis CI (
.travis.yml) - 2 spaces - GitLab CI (
.gitlab-ci.yml) - 2 spaces - Jenkins (
Jenkinsfile) - 4 spaces
JavaScript/TypeScript Ecosystem:
- Prettier config (
.prettierrc, etc.) - 2 spaces - ESLint config (
.eslintrc, etc.) - 2 spaces - Biome config (
biome.json) - 2 spaces - TSConfig (
tsconfig.json) - 2 spaces - Babel config (
.babelrc, etc.) - 2 spaces
Bundlers & Test Runners:
- webpack, Vite, Rollup configs - 2 spaces
- Jest, Vitest configs - 2 spaces
Linters:
- Stylelint config (
.stylelintrc) - 2 spaces
Dependency Management:
- Renovate config (
renovate.json) - 2 spaces - Dependabot (
.github/dependabot.yml) - 2 spaces
Build Systems:
- CMake (
CMakeLists.txt,*.cmake) - 2 spaces - Bazel (
BUILD,WORKSPACE) - 2 spaces - Gradle (
.gradle,.gradle.kts) - 4 spaces - Taskfile (
Taskfile.yml) - 2 spaces
Other:
- GraphQL, Prisma - 2 spaces
- Protocol Buffers - 2 spaces
Git:
.gitignore,.gitattributes,.gitconfig- 2 spaces
Project Documentation:
README,LICENSE,CHANGELOG- trimmed whitespace, 80 char maxCONTRIBUTING,CODE_OF_CONDUCT- 80 char max
Scripts:
- Shell scripts (
.sh,.bash,.zsh,.fish) - 2 spaces - Batch files (
.bat,.cmd) - 2 spaces, CRLF line endings - PowerShell (
.ps1,.psd1,.psm1) - 4 spaces, CRLF line endings
Build Requirements:
- Makefiles - tabs (required by Make)
Server Configs:
- Apache (
.htaccess) - 2 spaces - Nginx (
nginx.conf) - 4 spaces - Caddy (
Caddyfile) - 2 spaces
Environment:
.env,.env.*- 2 spaces, no final newline
Binary Files:
- Images, fonts, archives - all formatting disabled to prevent corruption
This configuration follows official style guides and community standards:
| Language/Type | Indent | Size | Max Length | Notes |
|---|---|---|---|---|
| JavaScript/TypeScript | spaces | 2 | 120 | Single quotes, standard in React/Vue/Node |
| JSON/YAML | spaces | 2 | 120 | YAML requires spaces |
| Python | spaces | 4 | 88 | Black formatter default |
| Go | tabs | - | 120 | Required by go fmt |
| Rust | spaces | 4 | 100 | Rustfmt default |
| Ruby | spaces | 2 | 120 | Community standard |
| Java/C#/C/C++ | spaces | 4 | 120 | Industry standard |
| PHP | spaces | 4 | 120 | PSR-2/PSR-12 standard |
| HTML/CSS | spaces | 2 | 120 | Web development standard |
| Markdown | spaces | 2 | 80 | Readability, preserves trailing spaces |
| Makefiles | tabs | 4 | - | Make requires tabs |
| Shell scripts | spaces | 2 | 120 | Common practice |
| Windows scripts | spaces | 2/4 | 120 | CRLF line endings required |
Simply place the .editorconfig file in your project root and commit it:
git add .editorconfig
git commit -m "chore: add EditorConfig for consistent formatting"Your editor will automatically apply the rules when you open files.
Create sections for project-specific overrides. More specific patterns override general ones:
# Your custom override (add to the end of .editorconfig)
[src/legacy/*.js]
indent_size = 4 # Override 2-space default for legacy code# MyLang support
[*.mylang]
indent_style = space
indent_size = 2
max_line_length = 100Create additional .editorconfig files in subdirectories (without root = true):
# In src/generated/.editorconfig
[*]
insert_final_newline = false
max_line_length = offEditorConfig is natively supported or has plugins for all major editors:
Built-in Support:
- VS Code
- JetBrains IDEs (IntelliJ IDEA, WebStorm, PyCharm, RubyMine, etc.)
- Visual Studio 2017+
- GitHub (respects EditorConfig in web editor)
Plugin Available:
- Sublime Text (EditorConfig package)
- Atom (editorconfig package)
- Vim/Neovim (editorconfig-vim)
- Emacs (editorconfig-emacs)
- Notepad++ (EditorConfig plugin)
See the official download page for complete list and installation instructions.
Most editors will show they're using EditorConfig:
- VS Code: Look for "EditorConfig" in status bar
- JetBrains: File → Settings → Editor → Code Style → enable "Enable EditorConfig support"
Prettier respects EditorConfig automatically. EditorConfig settings take precedence for:
indent_style→ Prettier'suseTabsindent_size→ Prettier'stabWidthmax_line_length→ Prettier'sprintWidthend_of_line→ Prettier'sendOfLine
You can override in .prettierrc:
{
"printWidth": 100
}Configure ESLint to respect EditorConfig with the plugin:
npm install --save-dev eslint-plugin-editorconfig{
"extends": ["plugin:editorconfig/all"]
}Or use specific rules:
{
"rules": {
"indent": ["error", "tab"] // Syncs with EditorConfig
}
}Black respects max_line_length from EditorConfig automatically. This config uses 88 characters to match Black's default.
Override in pyproject.toml if needed:
[tool.black]
line-length = 100Configure rustfmt to read from EditorConfig in rustfmt.toml:
edition = "2021"
# max_width is read from EditorConfig max_line_lengthEditorConfig handles formatting; use .gitattributes for line ending conversion during checkout:
# .gitattributes
* text=auto
*.sh text eol=lf
*.bat text eol=crlf.editorconfig # Root config (this file)
packages/
frontend/
.editorconfig # Frontend-specific overrides (no root = true)
backend/
.editorconfig # Backend-specific overrides (no root = true)
The comprehensive nature of this config means it works well for polyglot projects:
project/
frontend/ # JavaScript/TypeScript (2 spaces)
backend/ # Python (4 spaces, 88 chars)
infrastructure/ # Terraform (2 spaces)
.editorconfig # Handles all of them
Exclude legacy directories from strict formatting:
# Add to your .editorconfig
[legacy/**/*]
indent_size = unset
max_line_length = unsetThis configuration follows these principles:
- Standards-first: Use official style guides and community conventions
- Comprehensive: Cover the most common languages and tools developers encounter
- Sensible defaults: Choose widely-accepted settings that work for most projects
- Easy to customize: Well-commented and logically structured for easy modification
- Production-ready: Tested across multiple projects and teams
- Tool-friendly: Works alongside formatters like Prettier, Black, and rustfmt
- Clear organization: Grouped by category with explanatory comments
- Developers use different editor settings
- Mixed tabs and spaces in the same file
- Inconsistent line endings cause Git conflicts
- Windows developers create files with CRLF, breaking Unix scripts
- No clear project standards
- Code review noise from formatting differences
- New team members don't know the formatting conventions
- Instant consistency across the entire team
- Works automatically with any editor
- No per-developer configuration needed
- Follows industry best practices for each language
- Reduces "formatting wars" discussions
- New team members get correct formatting immediately
- Integrates seamlessly with formatters and linters
- Single source of truth for basic formatting rules
Q: Why use spaces instead of tabs for most languages?
A: Most modern style guides prefer spaces for consistency across different editor tab-width settings. Tabs are used only where required (Makefiles) or strongly preferred by the language tooling (Go).
Q: Can I use this with Prettier/ESLint/Black?
A: Yes! Most modern formatters respect EditorConfig. EditorConfig provides baseline formatting (indentation, line endings), while formatters handle more complex rules (semicolons, quotes, etc.).
Q: Why 2 spaces for JavaScript instead of 4?
A: 2 spaces is the most common convention in modern JavaScript/TypeScript (Airbnb, Google, StandardJS). It's standard in React, Vue, Angular, and Node.js projects.
Q: Do I need to install anything?
A: Most modern editors have built-in EditorConfig support. Older editors may need a plugin. Check editorconfig.org/#download.
Q: Should I commit this file?
A: Yes! Always commit .editorconfig so all team members and CI/CD systems use the same formatting rules.
Q: What if my team uses different conventions?
A: Fork this repository and modify to match your team's standards. Or simply edit your copy to override specific sections.
Q: Why is max_line_length 120 instead of 80?
A: Modern screens are wider, and 120 is a good balance between readability and screen real estate. Specific languages use their community standards (Python: 88, Rust: 100, Markdown: 80).
Q: Will this slow down my editor?
A: No. EditorConfig processing is extremely fast and happens only when opening files.
Q: Can I use multiple .editorconfig files?
A: Yes! EditorConfig searches from the current directory up to the project root. You can have directory-specific configs (just don't include root = true in them).
Q: What about binary files?
A: All formatting rules are disabled for binary files (images, fonts, archives) to prevent corruption.
-
Check editor support: Verify your editor has EditorConfig enabled
- VS Code: Built-in, check status bar
- JetBrains: Enable in Settings → Editor → Code Style
- Other editors: Install plugin from editorconfig.org
-
Check file pattern: Ensure the glob pattern matches your file
# Test if .editorconfig would match your file # (no built-in tool, but check patterns manually)
-
Check pattern order: Later patterns override earlier ones
- More specific patterns should come after general ones
-
Check root directive: Multiple
root = truecan cause issues- Only the top-most
.editorconfigshould haveroot = true
- Only the top-most
EditorConfig only affects new edits, not existing content. To reformat:
VS Code:
Shift+Alt+F (Windows/Linux)
Shift+Option+F (macOS)
JetBrains:
Ctrl+Alt+L (Windows/Linux)
Cmd+Option+L (macOS)
Command line with Prettier:
npx prettier --write "**/*"If you see ^M characters or Git shows every line changed:
-
Configure Git to normalize line endings:
git config --global core.autocrlf input # Unix/Mac git config --global core.autocrlf true # Windows
-
Create
.gitattributes:* text=auto
-
Re-normalize the repository:
git add --renormalize . git commit -m "chore: normalize line endings"
Issues and pull requests are welcome!
Found a problem or have a suggestion? Open an issue.
- Fork the repository
- Create a feature branch (
git checkout -b feat/add-amazing-language) - Make your changes to
.editorconfig - Ensure conventions follow the language's official style guide
- Add comments explaining non-obvious choices
- Commit your changes (
git commit -m 'feat: add support for AmazingLang') - Push to the branch (
git push origin feat/add-amazing-language) - Open a Pull Request
When adding a new language:
- Research: Check the language's official style guide and community conventions
- Glob patterns: Include all relevant file extensions
- Indentation: Set correct style (spaces/tabs) and size
- Line length: Set
max_line_lengthif the language has a convention - Comments: Explain non-obvious choices
- Organization: Group with similar languages
- Ordering: Maintain logical ordering within categories
Example:
# AwesomeLang - follows AwesomeLang official style guide v2.0
[*.{awsl,awesome}]
indent_style = space
indent_size = 3
max_line_length = 100- EditorConfig Official Site
- EditorConfig Specification
- Editor Plugins
- EditorConfig on GitHub
- Glob Pattern Reference
Frédérique Mittelstaedt
- GitHub: @gfmio
- The EditorConfig team for creating this essential tool
- Language communities for establishing and documenting style conventions
- Contributors who help improve this configuration