Feature Request: Project-specific snippets

Asked by John Szakmeister

I'm an open-source developer, and have contributed to a number of projects over the years. I'm also a consultant, and have been involved in many work-related projects too. I find myself wanting to standardize on a set of snippet names that automatically adjusts to the coding style/convention for the projects I work on. For instance, Subversion's style is different than that of gcc, which in different than the Linux kernel, and I'd like "func" to create a function in the correct style for each project.

What I'd like to do is "override" a set of snippets dynamically. Ideally the search path would be based on the buffer I'm working in too. I've been using localvimrc to customize settings, and it would be nice to leverage that to get project-specific snippets. The only catch is that to be safe, localvimrc is sandboxed by default.

BTW, thank you for such a wonderful plugin. It's definitely a tool I reach for often.

Question information

Language:
English Edit question
Status:
Solved
For:
UltiSnips Edit question
Assignee:
No assignee Edit question
Solved by:
John Szakmeister
Solved:
Last query:
Last reply:
Revision history for this message
SirVer (sirver) said :
#1

Thanks for the kind words.

You can do that already what you want to achieve. Set for all your projects your in your local vimrc the variable:

g:UltiSnipsSnippetDirectories = ["UltiSnips", "MyLocalProjectName"]

and you can pack your snippets somewhere in your runtimepath into the MyLocalProjectName/<filetype>.snippets file - it will only be sourced for your current project. obiously, you can also change this for each and every buffer (via an autocommand for example), so you should be all set.

Revision history for this message
John Szakmeister (jszakmeister) said :
#2

Thank you for the answer. I had thought about this solution, but it felt wrong to be manipulating a global option this way. It almost feels like there should be a buffer-local version that you could use instead. But I've got something put together that seems to work reasonably well.

Thanks again!