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

23,021

Solution 1

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

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

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

Solution 3

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

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.

Share:
23,021
Geir Sagberg
Author by

Geir Sagberg

System developer at Bekk Consulting

Updated on November 26, 2020

Comments

  • Geir Sagberg
    Geir Sagberg over 3 years

    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?

  • Brian FitzGerald
    Brian FitzGerald over 8 years
    I wanted to accomplish the same thing as OP, but for what it's worth, Sublime Text 3 cpu usage spikes for me with "binary_file_patterns." Unfortunately, I can only get it to calm down by using "folder_exclude_patterns." I am on a late 2013 Macbook Pro.
  • t.mikael.d
    t.mikael.d about 8 years
    I've got the same issue as @BrianFitzGerald, have to use folder_exclude_patterns when on OS X. (ST Build 3103, OS X 10.11)
  • xiao
    xiao almost 8 years
    This is not the solution if you still want the folders to show on the sidebar.
  • JohnnyQ
    JohnnyQ over 7 years
    Works for me in the latest Sublime Text version Build 3126 on OSX El Capitan.
  • Mrchief
    Mrchief over 7 years
    To exclude files from the index but keep them in the sidebar... This is pure genius!
  • Vishal Sakaria
    Vishal Sakaria about 7 years
    This only shows the node_modules folder but not the sub folder so doesn't really work.
  • Paul Wenzel
    Paul Wenzel about 7 years
    As of March 2017, the Sublime Text 3 preference is index_exclude_patterns, e.g. "index_exclude_patterns": ["*.log","node_modules/**","bower_components/**"]
  • Michael
    Michael about 7 years
    @PaulWenzel I just discovered that setting, but when I do a Find in Files, those show up. Is it only for indexing meta constructs like function names?
  • Paul Wenzel
    Paul Wenzel about 7 years
    @Michael I read that "folder_exclude_patterns": ["name_of_folder"] might help remove certain patterns from search results, but I haven't tested it. Source: coderwall.com/p/bk90bw/…
  • olistik
    olistik over 5 years
    @Michael I can confirm that index_exclude_patterns doesn't hide node_modules's files from the "Goto Anything" (⌘P) search: "index_exclude_patterns": ["*.log", "node_modules/**"], Tested with Sublime Text 3.1.1, Build 3176.
  • olistik
    olistik over 5 years
    So far the only working solution has been binary_file_patterns.
  • Nishant
    Nishant about 5 years
    Why two asterisks? Also I want to exclude all of a folder except JSON file in that folder. Could you suggest a way for this?
  • BYTE RIDER
    BYTE RIDER almost 5 years
    I use this to hide and ignore folders with command-P: "folder_exclude_patterns": ["build/**", ".gradle", "node_modules/**"],
  • Michael
    Michael over 3 years
    @Nishant Two asterisks are not actually necessary. /* and */ are treated as globs.