0

I have tried other solutions proposed of this question but still none of them worked.

Related config:

Plugin 'SirVer/ultisnips'
" Optional:
Plugin 'honza/vim-snippets'

let g:UltiSnipsSnippetDirectories = ['/home/ayush/.vim/bundle/ultisnips', '~/UltiSnips']
let g:UltiSnipsExpandTrigger="<tab>"
let g:UltiSnipsJumpForwardTrigger="<c-b>"
let g:UltiSnipsJumpBackwardTrigger="<c-z>"
let g:UltiSnipsEditSplit="vertical"

I use vundle package manager and installed ultisnips by :PluginInstall

When creating new snips, :UltiSnipsEdit, it opens a file at ~/UltiSnips/<language>.snippets and i think vundle installed the package at ~/.vim/bundle/ultisnips.

Also, :verbose imap <tab> shows

 <Tab>       * <C-R>=UltiSnips#ExpandSnippet()<CR>    
Last set from ~/.vim/bundle/ultisnips/autoload/UltiSnips/map_keys.vim                                                                                 Press ENTER or type command to continue                                 

and :help UltiSnips-snippet-search-path shows E149: Sorry, no help for UltiSnips-snippet-search-path

If some more info is needed, please mention in comments.

  • You need to change the directories in g:UltiSnipsSnippetDirectories to the ones you installed with the plugin by Honza. – klaus May 9 '19 at 8:25
  • I didn't specified any folder, i just used PluginInstall which install in the default directory, ~/.vim/bundle/<plugin> which i have specified. Am i missing something? – kayush May 9 '19 at 10:19
  • Read the document about the directories. I know the docs is huge, but most of it is just talking about the same thing over and over. So, just skim through it. – klaus May 9 '19 at 11:25
  • 2
    Start with a minimal vimrc and a test snippet. Run these 4 shell commands. The last one should start Vim in a buffer where trigger has been written; press Tab to expand the snippet. If it's not expanded, something is wrong in your Vim build (try to recompile a more recent version with more features), or something is wrong in your UltiSnips plugin (make sure it's correctly installed), or something in your environment intercepts Tab before Vim. – user938271 May 9 '19 at 19:43
  • If it is expanded, you have a working starting point. From there, progressively re-include your custom Vim config and your snippets, until something breaks. When that happens, you'll have a MCVE. Post it here. – user938271 May 9 '19 at 19:43
2

g:UltiSnipsSnippetDirectories are used to search snippets, it's default to ['UltiSnips'], there are 2 kinds of settings:

relative path

 let g:UltiSnipsSnippetDirectories = ['UltiSnips','foo']

UltiSips will loop each path in runtimepath to search for child directory named UltiSnips and foo, and use them as snippets source.

Note that "snippets" is reserved for snipMate snippets and cannot be used in this list.

absolute path, one entry only

let g:UltiSnipsSnippetDirectories = [$HOME.'/.vim/UltiSnips']

UltiSnips will search snippets from and only from this directory.

Also check :h UltiSnips-how-snippets-are-loaded if you have doubts.

Your g:UltiSnipsSnippetDirectories are two absolute paths, it's a mistake.

Also note that ultisnips itself doesn't contain snippets, it doesn't have a UltiSnips child directory.


g:UltiSnipsSnippetsDir is your private snippets directory. But by default it's not defined.

g:UltiSnipsSnippetsDir
                            Defines the directory where private snippet
                            definition files are placed in in.

                            As example, if the current 'filetype' is "cpp" the
                            :UltiSnipsEdit command looks for a file to edit in
                            this order:
                            1. An existing
                               g:UltiSnipsSnippetsDir."/cpp.snippets" file
                            2. Find a matching "cpp" snippets file in
                               g:UltiSnipsSnippetDirectories
                            3. Create a new
                               g:UltiSnipsSnippetsDir."/cpp.snippets" file

Don't mix up g:UltiSnipsSnippetsDir and g:UltiSnipsSnippetDirectories.


common setting

let g:UltiSnipsSnippetsDir = $HOME.'/.vim/UltiSnips'

Don't change g:UltiSnipsSnippetDirectories. UltiSnips will loop each path in your runtimepath to find subdirectory named UltiSnips as snippets source, when you call UltiSnipsEdit, it will open your private snippets if you already have one.

Note that g:UltiSnipsSnippetsDir must be a child directory of one of runtimepath.

  • I removed let g:UltiSnipsSnippetDirectories = ['/home/ayush/.vim/bundle/ultisnips', '~/UltiSnips'] and added let g:UltiSnipsSnippetsDir = $HOME.'/.vim/UltiSnips' Still tab is not working. – kayush May 9 '19 at 17:16
  • +1 It works now. Thanks – kayush May 10 '19 at 2:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.