The Files and Workspaces settings category allows you to configure how Visual Studio Code handles files, folders, and workspaces, streamlining project management and file type associations.
files.associations
You can associate file extensions with specific language modes. This is crucial for syntax highlighting, IntelliSense, and language-specific features.
"files.associations": {
"*.module.css": "css",
"*.component.ts": "typescriptreact"
}
You can also override language detection for specific files using glob patterns:
"files.associations": {
"**/*.conf": "ini" // Treat all .conf files as INI files
}
files.exclude
Specify file patterns to exclude from the Explorer, Search, and Go to File. Useful for hiding build artifacts, dependency folders (like node_modules
), and temporary files.
"files.exclude": {
"**/.git": true,
"**/node_modules": true,
"**/build": true,
"**/dist": true
}
This one probably makes more sense as a workspace setting since most of the normal culprits are already included by default.
Setting a Default Language for Empty Files: files.defaultLanguage
files.defaultLanguage
lets you set the default language mode for new files or files without a recognized extension.
Depending on the project, I will typically set this to either markdown
or typescript
.
Auto Save (files.autoSave
)
To maintain a smooth workflow without constantly worrying about saving your work, consider enabling files.autoSave
. This setting automatically saves your changes either after a specified delay or when focus shifts away from the editor. This ensures your work is always up to date and can help prevent accidental data loss.
"files.autoSave": "afterDelay",
"files.autoSaveDelay": 1000
Trim Trailing Whitespace : files.trimTrailingWhitespace
Clean code is easier to maintain and review. By enabling files.trimTrailingWhitespace
, Visual Studio Code will automatically remove any extra spaces at the end of lines whenever you save a file. This not only improves the aesthetics of your code but also helps prevent unnecessary diffs in version control.
"files.trimTrailingWhitespace": true
Insert Final Newline: files.insertFinalNewline
Some coding standards require that files end with a newline character. With the files.insertFinalNewline
setting, VS Code automatically adds a newline at the end of a file upon saving. This small tweak can help avoid warnings from linters and ensure consistency across your codebase.
"files.insertFinalNewline": true