brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: an .editorconfig file keeps indentation the same in every editor

Config
~/tips/tip-config-editorconfig-file

root = true

Put indent and line ending rules in the project, so editors follow them.

Tabs in one file, four spaces in the next, Windows line endings sneaking in. A small .editorconfig file in the project root settles most of that before it reaches a diff.

This is a reasonable starting point:

root = true

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

[*.py]
indent_size = 4

[Makefile]
indent_style = tab

Sections match file names, and later ones override earlier ones for the files they match. The root = true line at the top tells editors to stop looking for more of these files in parent folders.

Commit the file and everyone who opens the project gets the same rules, whatever their personal settings are. I find it much friendlier than a paragraph in a contributing guide that nobody reads.

Support varies. Some editors read the file natively, including Neovim, WebStorm and Xcode, while others need a plugin, Visual Studio Code among them. Also, these settings apply to what you type and save from now on. Existing files don’t get reformatted, so a project with mixed indentation stays mixed until you run a formatter over it.

Further reading: EditorConfig

Going deeper: Guide: advanced tmux, a config that grows with you, formats, layouts and more

More Config tips include extraconfig.txt npm config list –smart-case define( 'WP_HOME', 'https://example.com' ); jellyfin --cachedir /srv/jellyfin-cache All Config tips (9) All topics

Link