4

I tried to save the snippet files in the project folder but it is doesn't work. Do you have any other idea?

1 Answer 1

5

With a custom plugin

EDIT: a generalisation of the following plugin has been published at https://packagecontrol.io/packages/ProjectCompletions

If you put this plugin in your User folder under the name ProjectCompletions.py

import sublime_plugin

class ProjectCompletions(sublime_plugin.EventListener):

    def on_query_completions(self, view, prefix, locations):
        return view.window().project_data().get("completions")

You can inject completions using a "completions" entry in your project file:

{
  "folders": ...
  "completions":[
      ["I", "I am a ${1:snippet} baby!"]
  ]
}

The format for completions is [trigger, snippet]. More elaborate approaches are possible so that the scope is also taken in account.

Animated Gif


In an indirect way using the ProjectSpecific plugin

With that installed, you can use the settings key of your project file to install additional commands. Then to enable a snippet you can add this to your project:

{
    "folders": ...
    "settings": {
        "project-specific": {
            "sublime-commands": [
                {"caption": "My Snippet",
                 "command": "insert_snippet",
                 "args": {"contents": "I am a ${1:snippet} baby!"} }
            ]
        }
    ...
    }

}

and you'll find the "My Snippet" command in the command palette only in the current project.

You can also bind keys in a project specific way. By binding them to the insert_snippet command you can achieve a similar effect without having to go through the palette.

6
  • Thank you, but it is not a snippet, (snippet are autocompleted...) Commented Sep 16, 2015 at 20:26
  • 1
    @Amina with a custom plugin it is easy to get autocompletion (see edit)
    – Bordaigorl
    Commented Sep 17, 2015 at 8:23
  • WOW!!! Thank you very much, tested and working great. I want to give you half of my reputation score :) Commented Sep 17, 2015 at 8:47
  • 1
    If I find the time I will package it for Package Control, it may be useful for others too (me included!)
    – Bordaigorl
    Commented Sep 17, 2015 at 12:02
  • 3
    @Amina just published! packagecontrol.io/packages/ProjectCompletions (it supports scope-specific completions as well, see readme)
    – Bordaigorl
    Commented Sep 17, 2015 at 14:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .