From 02bb389c0a622754e70d58ae328587bb0ba5e491 Mon Sep 17 00:00:00 2001 From: Martin Tournoij Date: Wed, 29 Nov 2017 11:51:28 +0000 Subject: [PATCH] Support multiple directories in g:minisnip_dir (#5) * Support multiple directories in g:minisnip_dir The specific reason I added this is because I wanted to add support for minisnip in vim-go (it already supports ultisnips and neosnippet). However, with just a single directory I can't add the vim-go snippet directory. This converts g:minisnip_dir to a colon-separated list of paths, like the PATH environment variable. There are several ways to do this; I just chose this as the easiest and most backwards compatible way. * Update documentation Also fix some small typos in the documentation, and improve the `autocmd` example to be more general, as well as making sure it works only for the current buffer by using `setlocal` --- .gitignore | 1 + autoload/minisnip.vim | 24 +++++++++++++----------- doc/minisnip.txt | 17 +++++++++-------- 3 files changed, 23 insertions(+), 19 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0a56e3f --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/doc/tags diff --git a/autoload/minisnip.vim b/autoload/minisnip.vim index 7403cd8..626a5e2 100644 --- a/autoload/minisnip.vim +++ b/autoload/minisnip.vim @@ -3,18 +3,20 @@ function! minisnip#ShouldTrigger() let l:cword = matchstr(getline('.'), '\v\f+%' . col('.') . 'c') " look for a snippet by that name - let l:snippetfile = g:minisnip_dir . '/' . l:cword - let l:ft_snippetfile = g:minisnip_dir . '/_' . &filetype . '_' . l:cword - if filereadable(l:ft_snippetfile) - " filetype snippets override general snippets - let l:snippetfile = l:ft_snippetfile - endif + for l:dir in split(g:minisnip_dir, ':') + let l:snippetfile = l:dir . '/' . l:cword + let l:ft_snippetfile = l:dir . '/_' . &filetype . '_' . l:cword + if filereadable(l:ft_snippetfile) + " filetype snippets override general snippets + let l:snippetfile = l:ft_snippetfile + endif - " make sure the snippet exists - if filereadable(l:snippetfile) - let s:snippetfile = l:snippetfile - return 1 - endif + " make sure the snippet exists + if filereadable(l:snippetfile) + let s:snippetfile = l:snippetfile + return 1 + endif + endfor return search(g:minisnip_delimpat, 'e') endfunction diff --git a/doc/minisnip.txt b/doc/minisnip.txt index 513c1a1..584145b 100644 --- a/doc/minisnip.txt +++ b/doc/minisnip.txt @@ -44,11 +44,12 @@ CONFIGURATION *minisnip-configuration* ------------------------------------------------------------------------------- *'g:minisnip_dir'* -Default: $HOME . '/.vim/minisnip' +Default: '~/.vim/minisnip' -This allows you to specify where minisnip looks for snippet files. Add this -line to your `.vimrc`: > - let g:minisnip_dir = '/path/to/directory' +A colon-separated list of directories to look for snippet files, similar to +$PATH. The first match will be used. For example to share system-wide +snippets: > + let g:minisnip_dir = '/usr/share/minisnip:~/.vim/minisnip' < ------------------------------------------------------------------------------- @@ -66,7 +67,7 @@ example: > *'g:minisnip_enddelim'* Defaults: '{{+', '+}}' -The start and end delimeters of the placeholder string to use. For example, +The start and end delimiters of the placeholder string to use. For example, with the default values, a sample snippet could look like this: > @@ -83,7 +84,7 @@ with the default values, a sample snippet could look like this: > *'g:minisnip_evalmarker'* Default: '~' -Marks a template as meant to be executed as vimscript. With the default value, +Marks a template as meant to be executed as VimScript. With the default value, this looks something like: > It has been {{+~localtime()+}} seconds since the Unix epoch < @@ -113,7 +114,7 @@ MISCELLANEOUS *minisnip-miscellaneous* Syntax highlighting for minisnips: -If you would like to have the minisnip delimeters hightlighted for better +If you would like to have the minisnip delimiters highlighted for better visibility in your minisnip files, add the following to your `.vimrc`: > - autocmd BufRead,BufNewFile /path/to/minisnips/* set filetype=minisnip + autocmd BufRead,BufNewFile */minisnip/_* setlocal filetype=minisnip <