Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lazy loading Ultisnips and custom snippets #280

Closed
pgilad opened this issue Apr 19, 2014 · 9 comments
Closed

Lazy loading Ultisnips and custom snippets #280

pgilad opened this issue Apr 19, 2014 · 9 comments

Comments

@pgilad
Copy link

pgilad commented Apr 19, 2014

Hi, I'm using NeoBundle to lazy load Ultisnips and Vim-Snippets in the following way:

NeoBundle 'honza/vim-snippets', {
            \ 'lazy': 1,
            \ 'autoload' : {
            \    'on_source': ['ultisnips']
            \  }
            \ }
NeoBundle 'SirVer/ultisnips', {
            \ 'depends': ['vim-snippets'],
            \ 'lazy': 1,
            \ 'autoload' : {
            \    'insert': 1
            \  }
            \ }

My intention is obviously to load Ultisnips only when going into insert mode, and then loading vim-snippets.

This works great the for supplied snippets in honza/vim-snippets but only after I re-open the current buffer, or edit a different buffer I can use my custom snippets.

My custom snippets work great alongside the factory snippets if I don't lazy load Ultisnips. They are defined like so:

set runtimepath+=~/.dotfiles
let g:UltiSnipsExpandTrigger="<tab>"
let g:UltiSnipsJumpForwardTrigger="<tab>"
let g:UltiSnipsJumpBackwardTrigger="<s-tab>"
let g:UltiSnipsSnippetsDir='~/.dotfiles/mysnippets'
let g:UltiSnipsSnippetDirectories=['UltiSnips', 'mysnippets']

Any help on how to successfully lazy load both plugins and have them work the second I enter insert mode in the same buffer?

@SirVer
Copy link
Owner

SirVer commented Apr 20, 2014

Lazy Loading is not supported by Vim in any way, i.e. it is a hack by your plugin manager. UltiSnips needs to know the runtimepath of snippets it should load, which is conflicting with lazy loading obviously. So no, there is no support from UltiSnips for this.

@SirVer SirVer closed this as completed Apr 20, 2014
@Shougo
Copy link

Shougo commented Apr 20, 2014

I think you must initialization your custom snippet directory before UltiSnips loading.

@pgilad
Copy link
Author

pgilad commented Apr 21, 2014

@Shougo Thanks for the tip! This actually work if I run call UltiSnips#FileTypeChanged() this works. Now gotta figure out how to run this on autoload and we'll be set!
@SirVer Thanks anyway!

@pgilad
Copy link
Author

pgilad commented Apr 23, 2014

If anyone's interested the following setup works for me allowing me to lazy load Ultisnips & Vim-Snippets:

set runtimepath+=~/.dotfiles
let g:UltiSnipsExpandTrigger="<tab>"
let g:UltiSnipsJumpForwardTrigger="<tab>"
let g:UltiSnipsJumpBackwardTrigger="<s-tab>"
let g:UltiSnipsSnippetsDir='~/.dotfiles/mysnippets'
let g:UltiSnipsSnippetDirectories=['UltiSnips', 'mysnippets']

NeoBundle 'honza/vim-snippets', {
            \ 'lazy': 1,
            \ 'autoload': {
            \ 'on_source': ['ultisnips']
            \}
            \}
NeoBundle 'SirVer/ultisnips', {
            \ 'lazy': 1,
            \ 'autoload' : {
            \    'insert': 1
            \  }
            \ }
if neobundle#tap('ultisnips')
    function! neobundle#hooks.on_source(bundle)
        silent! call UltiSnips#FileTypeChanged()
    endfunction
    call neobundle#untap()
endif

@SirVer would it be interesting to add as a PR to the readme?

@SirVer
Copy link
Owner

SirVer commented Apr 23, 2014

Nope, that is too fragile for me to support it. I can point users here now though..

@kshenoy
Copy link

kshenoy commented Feb 6, 2015

@pgilad Thanks! I was looking for something similar. Do you know if it's possible to enhance this by loading only when UltiSnips is triggered and not just enter insert mode?

@pgilad
Copy link
Author

pgilad commented Feb 7, 2015

Depends on what you mean by "UltiSnips is triggered"

@kshenoy
Copy link

kshenoy commented Feb 7, 2015

I mean, when you press <Tab> in insert mode i.e. when the UltiSnips#ExpandSnippetOrJump() is called.

@pgilad
Copy link
Author

pgilad commented Feb 7, 2015

Yeah it's definitely possible. I would look into NeoBundle functions or function_prefix for autoload. (https://github.com/Shougo/neobundle.vim/blob/0b44247d063838e7709aeb225727020080cdc454/doc/neobundle.txt#L1051)

rubdos pushed a commit to rubdos/ultisnips that referenced this issue Oct 21, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants