Siddharth Thevaril
Siddharth Thevaril

Reputation: 3798

How to enable/disable certain snippets for specific projects in Sublime Text?

I work on Sublime Text 3 and I've installed many snippets for different PHP frameworks for example Codeigniter and Laravel.

Is there any way I can select which snippets to enable for a project? As in if I work on Laravel, the Codeigniter snippets shouldn't show and vice versa?

Upvotes: 1

Views: 574

Answers (2)

Gerard Roche
Gerard Roche

Reputation: 6391

No, this is isn't possible. There is a feature request for snippet exclusion patterns.

A workaround is to separate the snippets into individual packages, then use Package Control to enable and disable the packages on-the-fly (via the Command Palette Ctrl+Shift+P).

Create individual packages in the following layout:

\
+-Packages
      +- snippets_package_name_a
      |       \-*.sublime-snippet
      +- snippets_package_name_b
      |       \-*.sublime-snippet
      ...

Find the Packages directory: Menu > Preferences > Browse Packages....

Open the Command Palette: Ctrl+Shift+P

Type the commands:

  • Package Control: Enable Package
  • Package Control: Disable Package

Upvotes: 1

MattDMo
MattDMo

Reputation: 102892

Yes, this is quite simple to do. Assuming you have a .sublime-project file defined for your current project, select Project → Edit Project, and in the "settings" dict add "ignored_packages": [] and in the array add the package(s) you want to ignore. Here's an example:

{
    "folders":
    [
        {
            "follow_symlinks": true,
            "path": "/home/mattdmo/Projects/laravel_project_1"
        }
    ],
    "settings":
    {
        "ignored_packages": [
            "CodeIgniter Snippets",
            "CodeIgniter Utilities"
        ]
    }
}

The named packages will only be ignored in this project. For a CodeIgniter project, just add your Laravel-related packages.

Upvotes: 0

Related Questions