1

I installed UltiSnips with Vundle by placing

Plugin 'SirVer/ultisnips'¬
Plugin 'honza/vim-snippets'

in my .vimrc as well as this as it says in the readme

let g:UltiSnipsExpandTrigger="<tab>"
let g:UltiSnipsJumpForwardTrigger="<c-b>"
let g:UltiSnipsJumpBackwardTrigger="<c-z>"

I installed the plugin with :PluginInstall and after restarting vim I can see that the plugin is installed by :UltiSnipsEdit which opens a new window to add snippets. I added a basic example and save the file which is saved to the project directory in ./UltiSnips/html.snippets

snippet nn
<header class="main-header"></header>
endsnippet

Now I expect nn to expand into my snippet content after writing it and hitting tab key. However, it did not happen. I tried disabling other plugins that I have installed and mapping expand trigger to a different key / keys but that did not work either. Is there something I am missing here?

9
  • what does set ft? say?
    – B.G.
    Commented Nov 3, 2017 at 12:04
  • if I run it while editing the file where I want to expand my snippet it returns filetype=html Commented Nov 5, 2017 at 1:27
  • Have you installed a Tab plugin (f.e. supertab)? do other snippets work?
    – B.G.
    Commented Nov 13, 2017 at 10:29
  • No I do not have a supertab plugin, I also tried disabling other plugins in my .vimrc file and reloading vim, but the problem remained Commented Nov 13, 2017 at 10:30
  • have you tried a default snippet? move your snippets to ~/.vim/UltiSnips and try again. I don't think the project folder will be searched.
    – B.G.
    Commented Nov 13, 2017 at 10:40

1 Answer 1

1

So after all the Problem is, that UltiSnips does not search the projectfolder for snippets.

If you read :h UltiSnips-snippet-search-path you can see, that it looks for all folders defined in g:UltiSnipsSnippetDirectories which are subfolders of a directory defined in the runtimepath option.

:h runtimepath shows that this depending on the OS but mostly something like:

                    Unix: "$HOME/.vim,
                    $VIM/vimfiles,
                    $VIMRUNTIME,
                    $VIM/vimfiles/after,
                    $HOME/.vim/after"

Now if you have a plugin manager, the runtimepath will be manipulated. So every folder in your .vim/bundle directory will be added to it.

Thats a fact UltiSnips actually uses for snippets in plugins. the vim-snippets Plugin for example has a folder UltiSnips which is automatically read by UltiSnips since the pluginmanager will add the plugin to the runtimepath

So for you that means, keep all your snippets in a UltiSnips folder somewhere in the runtimepath. Usually ~/.vim/UltiSnips.

There is no possibility for projectspecific snippets (There may be a plugin for that). And I see no reason why there should be projectspecific snippets other then different coding styles. But that is handled by other instruments. If you are interested here is a disscusion about it: https://github.com/SirVer/ultisnips/issues/222

For your issue with the UltiSnipsEdit command there is a g:UltiSnipsSnippetsDir variable. see :h UltiSnipsEdit

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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