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
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.
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.
-
Thank you, but it is not a snippet, (snippet are autocompleted...) Sep 16, 2015 at 20:26
-
1@Amina with a custom plugin it is easy to get autocompletion (see edit) 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 :) Sep 17, 2015 at 8:47
-
1If I find the time I will package it for Package Control, it may be useful for others too (me included!) Sep 17, 2015 at 12:02
-
3@Amina just published! packagecontrol.io/packages/ProjectCompletions (it supports scope-specific completions as well, see readme) Sep 17, 2015 at 14:46