ultisnips icon indicating copy to clipboard operation
ultisnips copied to clipboard

How do I define per-project snippets / boilerplate?

Open giddie opened this issue 4 years ago • 3 comments

I came across Issue #222, but I'm surprised that no-one else seems to have yet raised this usecase:

I would like to define some boilerplate for test files in a project. However, the setup for a given project is likely to be quite unique, so I'd like to define the snippet in a directory that is loaded only for that project.

The most obvious solution to me seems to be for UltiSnips to check the current working directory and parent directories for UltiSnips directories. Or is there a better solution to this that still uses runpaths?

giddie avatar Jun 09 '20 10:06 giddie

I've found a workaround for this that I'm reasonably happy with:

~/.vimrc

" Enable reading of local .vimrc / .nvimrc files in working directory
set exrc
[...]
" At the very bottom of the file:
set secure

~/Projects/MyProject/.vimrc

set runtimepath^=.vim

Snippets can then go in ~/Projects/MyProject/.vim/UltiSnips.

I do think this would be much easier if UltiSnips had an option to search for snippets from the CWD upwards. Either way, this seems to me like it would be quite a common usecase -- maybe worth documenting?

giddie avatar Jun 09 '20 14:06 giddie

set exrc is not safe, see https://github.com/vim/vim/issues/1015

Hritik14 avatar Apr 25 '24 10:04 Hritik14