65

Vim has this great plugin to convert the current project's .gitignore into a syntax understandable by Vim and from there exclude all those files from opening.

Using Sublime Text 3's 'Go to Anything' (CMD+P), I get lots of files I'm not interested in, such as stuff under .build and .meteor.

Is there something similar for ST3?

Jonatan Littke
  • 5,583
  • 3
  • 38
  • 40
  • You can manually add them to your project file, and it wouldn't be difficult to write a plugin to do it for you, but I don't know of one that already exists. – bheklilr Aug 29 '13 at 20:08
  • I added them for now. It's just that with so many projects, it'd take time. And `.gitignore` already exists in most repoes for almost the exact same file list. – Jonatan Littke Aug 30 '13 at 10:03
  • 2
    I understand the frustration. If I had the time, I'd work on writing a simple script to do it, but I don't think I'll have the opportunity for about 2 weeks. Do you know python at all? Parsing a `.gitignore` would be trivial, and shoving that into your project settings shouldn't be too terribly hard. There is a setting called `"file_exclude_patterns"` that is editor-wide, you could put your common ones there as a temporary fix. – bheklilr Aug 30 '13 at 12:23
  • 1
    Or even better, use the `git ls-files` command output to populate the file list. Parsing `.gitignore` file is not as trivial as it looks, as it has some specific formats you would need to reimplement by hand (e.g. lines starting with `!` are negated patterns). I think it would be better to let git do this work, as it knows how to do it. – MetalElf0 Jun 10 '14 at 14:13

4 Answers4

68

I created a quick-and-dirty plugin, sublime-gitignorer, to solve exactly this problem.

It is currently tested on Ubuntu and Windows in Sublime Text 2 and 3. I expect it will also work on any other Linux distro or on Mac.


To install, assuming you have package control, just:

  • Press CTRL+SHIFT+P (CMD+SHIFT+P on Mac)
  • Select "Install Package"
  • Search for the Gitignored File Excluder and press Enter.

Alternatively, if you don't have package control you can copy gitignore_plugin.py to your Packages directory, which you can locate by selecting Browse Packages... from the Preferences menu in Sublime. You should really get Package Control instead, though - it's useful.


I'm not kidding when I say this plugin is dirty. The way it works is that the plugin, every five seconds:

  • Checks for Git repos located within your open folders
  • Asks Git what paths are ignored in each of those repos
  • Adds those paths to the file_exclude_patterns and folder_exclude_patterns settings.

Seems to work okay for most users, though - at least as long as the folders you're opening in Sublime aren't too huge. The presence of giant folders (e.g a typical node_modules folder) can, in combination with this plugin, slow Sublime to a crawl.

Anyone looking to contribute or report bugs should check out the issues page.

Mark Amery
  • 143,130
  • 81
  • 406
  • 459
  • 1
    Warning for cygwin users: my sublime text crashed with an error that libiconv-2.dll was missing. Using `sublime-gitignorer` requires that you have git configured to work in the context of sublime text's environment (windows, in the case of windows sublime) – Blake Jul 18 '15 at 20:56
  • 1
    @Nishant yes it works but there is a noticable lag when interacting with Find & Replace UI. I'm guessing it's reading the gitignore file frequently. – png May 21 '19 at 22:40
  • Its now a built-in feature of SublimeText 4, which is mentioned below by https://stackoverflow.com/users/1489243/jacob-ford – John Paul Ashenfelter Dec 20 '22 at 16:29
8

You can get a list of all the ignored files with

git ls-files --others -i --exclude-standard

and then add this to your file_exclude_patterns in Sublime Text as bheklilr suggested.

Stephan Rodemeier
  • 717
  • 10
  • 24
7

Assuming you have Sublime 3 and already installed Package Manager:

  1. add repo https://github.com/apc999/sublime-text-gitignore
  2. add package sublime-text-gitignore
  3. use menu item : File->Exclude Git-ignored

Have fun:)

Gruber
  • 2,196
  • 5
  • 28
  • 50
head_thrash
  • 1,623
  • 1
  • 21
  • 26
7

Sublime Text 4 Build 4142 (released November 10, 2022) supports a new setting:

"goto_anything_exclude_gitignore": true,

Add it to your settings file and files that are ignored in .gitignore will get ignored in autocompletion/fuzzysearch/etc.

Jacob Ford
  • 4,553
  • 5
  • 27
  • 42
Bijan
  • 25,559
  • 8
  • 79
  • 71