SirVer / ultisnips

UltiSnips - The ultimate snippet solution for Vim. Send pull requests to SirVer/ultisnips!
GNU General Public License v3.0
7.54k stars 694 forks source link

How do I define per-project snippets / boilerplate? #1241

Open giddie opened 4 years ago

giddie commented 4 years ago

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 commented 4 years ago

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?

Hritik14 commented 6 months ago

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

Konfekt commented 4 months ago

Here's a safer alternative: https://github.com/MarcWeber/vim-addon-local-vimrc/