Boost VS Code Performance: Exclude Files for a Faster Editor
Optimize your VS Code experience by configuring these settings to exclude unnecessary files, improving search, navigation, and overall performance.
If you've ever noticed VS Code feeling sluggish, especially in larger projects, the culprit might be the editor trying to index and watch too many files. This is particularly true for version control directories, temporary files, and build outputs. Thankfully, VS Code provides settings to exclude these unnecessary files, significantly improving performance.
This post will explain two crucial settings: files.exclude
and files.watcherExclude
, and how they can boost your VS Code experience.
files.exclude
: This setting controls which files and folders are hidden from the Explorer pane, search results, Go to File (Ctrl+P or Cmd+P), and other file-related operations within VS Code. It doesn't prevent you from opening the files manually, but it keeps the editor focused on relevant project files.
Here's a common configuration for files.exclude
in your settings.json
(accessible via File > Preferences > Settings or Code > Preferences > Settings on macOS, then search for "files.exclude" and click "Edit in settings.json"):
JSON
"files.exclude": {
"**/.git": true,
"**/.svn": true,
"**/.hg": true,
"**/CVS": true,
"**/.DS_Store": true,
"**/tmp": true,
"**/node_modules": true,
"**/dist": true
},
Let's break down what each entry does:
**/.git
,**/.svn
,**/.hg
,**/CVS
: Excludes version control directories (Git, Subversion, Mercurial, CVS). These are essential for version control but rarely need to be directly interacted with in the editor.**/.DS_Store
: Excludes macOS metadata files.**/tmp
: Excludes temporary directories.**/node_modules
: Excludes Node.js dependency folders. These can be massive and significantly slow down VS Code if included.**/dist
: Excludes build output directories (often used for compiled code).
The **
wildcard matches any number of directories, so **/.git
will exclude .git
folders at any level of your project.
files.watcherExclude
: This setting is even more critical for performance. It tells VS Code's file watcher to ignore specific files and folders. The file watcher monitors changes on disk, triggering updates in the editor. Excluding frequently changing but irrelevant directories, like node_modules
and build outputs, drastically reduces CPU usage and improves responsiveness.
Here's a typical files.watcherExclude
configuration:
JSON
"files.watcherExclude": {
"**/.git/objects/**": true,
"**/.git/subtree-cache/**": true,
"**/node_modules/**": true,
"**/tmp/**": true,
"**/dist/**": true
}
Key differences from files.exclude
:
This setting specifically targets the file watcher.
It's crucial to exclude
node_modules
and build output directories here.More specific exclusions within the
.git
directory (objects
andsubtree-cache
) further optimize performance.
Why are these settings important?
Improved Performance: By excluding unnecessary files, VS Code uses less CPU and memory, leading to a smoother and more responsive experience.
Faster Search and Navigation: Searching and navigating within your project becomes much faster when irrelevant files are excluded.
Reduced Clutter: The Explorer pane becomes cleaner and easier to navigate, focusing on the files you actually need to work with.
In Conclusion:
By configuring files.exclude
and files.watcherExclude
in your VS Code settings, you can significantly improve the editor's performance, especially in larger projects. This simple change can make a world of difference in your daily workflow. Remember to adjust these settings to fit your specific project needs. For example, if you're working on a project that doesn't use Node.js, you can remove the node_modules
entries.