How can I exclude a folder from indexing in Sublime Text, while still showing it in the sidebar?

Sublimetext2Sublimetext3Sublimetext

Sublimetext2 Problem Overview


For a large project with many dependencies e.g. in the node_modules/ folder, I noticed frequent CPU spikes because of Sublime indexing all the files in the folder.

I know I can hide files and folders using the folder_exclude_patterns setting, but I still want the folder to be visible in the sidebar.

How can I keep e.g. node_modules/ in the sidebar, but exclude it from indexing?

Sublimetext2 Solutions


Solution 1 - Sublimetext2

To exclude files from the index but keep them in the sidebar, use the binary_file_patterns setting in your User Settings, for example:

"binary_file_patterns": [
  "*.jpg", "*.jpeg", "*.png", "*.gif", "*.ttf", "*.tga", "*.dds",
  "*.ico", "*.eot", "*.pdf", "*.swf", "*.jar", "*.zip",
  "node_modules/**",
  "bower_components/**"
]

Make sure to copy the values from your Settings - Default preferences (here shown as "*.jpg" etc.), or you will start indexing binary files.

Solution 2 - Sublimetext2

You can change your personal settings, in Preferences -> Settings - User, add:

{
	"folder_exclude_patterns":
	[
		".svn", ".git", ".hg", "CVS",
		"node_modules",
	],
}

Solution 3 - Sublimetext2

Sublime Text 3 now provides a way to exclude files and folders from indexing while keeping them in the sidebar:

  "index_exclude_patterns": [
  	"*.log",
  	"node_modules/*"
  ]

On my project I observed the following improvement in the indexing status menu after applying changes:

Before:

index "MyApp" collated in 0.70s from 73934 files
index "MyApp" is using 15167488 bytes for 54234 symbols across 1357673 locations

After:

index "MyApp" collated in 0.00s from 137 files
index "MyApp" is using 61440 bytes for 730 symbols across 4763 locations

Solution 4 - Sublimetext2

Doesn't work in ST3 (Build 3126).

You can show node modules folders in sidebar and hide files inside this way :

"file_exclude_patterns":
[
    ...,
    "node_modules/**"
]

If you want to hide subfolders from each node module :

"folder_exclude_patterns":
[
    "node_modules/*/**"
]

All files inside node_modules will be removed from search, but each node_module subfolder will be still visible in sidebar.

Solution 5 - Sublimetext2

I thought binary_file_patterns wasn't working, because I am in the habit of right-clicking my top level folder and choosing "Find in folder". folder_exclude_patterns works with this but binary_file_patterns still searches everything - because the "Where" field overrides the setting.

So you can either use the menu option Find > Find in files OR right click-your top level folder, choose "Find in folder" and then delete the text in the "Where" field so it shows the placeholder text "Open files and folders".

Obviously you still have to add this to Preferences/Settings:

    "binary_file_patterns": [
      "node_modules/",
    ],

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionGeir SagbergView Question on Stackoverflow
Solution 1 - Sublimetext2Geir SagbergView Answer on Stackoverflow
Solution 2 - Sublimetext2liutView Answer on Stackoverflow
Solution 3 - Sublimetext2Killian HuygheView Answer on Stackoverflow
Solution 4 - Sublimetext2migliView Answer on Stackoverflow
Solution 5 - Sublimetext2Little BrainView Answer on Stackoverflow