default snippets not loading when running ultisnips the default way

Asked by Jorge

Hi,

first of all thanks for your last screencast, it was quite nice. I noticed a typo,
I think it should be Episode and not "Epsiode" :)

I have a quick question, I may I shown you this before, I try to load some plugins only by demand,
so I have to function to load them.
For ultisnips I have

function! LoadUltisnips()
  if !(has('unix') && executable('cygpath'))
    "cygwin vim does not have python
    runtime bundle/ultisnips_rep/plugin/UltiSnips.vim
    exec "set runtimepath+=" . g:p0 . "/bundle/ultisnips_rep"
  endif
  nnoremap <f10> :call UltiSnips_ListSnippets()<cr>
endfunction
nnoremap <f10> :call LoadUltisnips()<cr>:call UltiSnips_ListSnippets()<CR>
inoremap <f10> <esc>:call LoadUltisnips()<cr>a<c-r>=UltiSnips_ExpandSnippet()<cr>

this used to work fine, from recently when I do this it does not load the snippets for the filetype I am currently in.
So if I am in a latex file after I have to do the following:

:UltiSnipsAddFiletypes tex

to be able to use the latex snippets (otherwise I just have the default snippets for all filetypes).

Can you think of a quick way of solving this?
If not don't worry, I read in other questions that you seem to be busy with other things, so I will just keep doing the

:UltiSnipsAddFiletypes tex

thing.

Thanks!

Question information

Language:
English Edit question
Status:
Solved
For:
UltiSnips Edit question
Assignee:
No assignee Edit question
Solved by:
SirVer
Solved:
Last query:
Last reply:
Revision history for this message
Best SirVer (sirver) said :
#1

Ooooh well. Too late to fix typos now. This is out of the door ;)

Have a look at the (newly added) ftdetect/UltiSnips.vim . It sets an auto command for then the filetype is set to setup the correct Snippets to load. Unfortunately this must happen before any other filetype plugin is loaded or run, so you will likely need this file there - which means that UltiSnips will always be loaded.

Revision history for this message
Jorge (skeept) said :
#2

Thanks,

I updated the function that loads the plugin to include the lines that you have in the ftdetect files and now it works again.

The new function is

function! LoadUltisnips()
  if has("python")
    runtime bundle/ultisnips_rep/plugin/UltiSnips.vim
    exec "set runtimepath+=" . g:p0 . "/bundle/ultisnips_rep"
    if has("autocmd")
      autocmd FileType * call UltiSnips_FileTypeChanged()
      autocmd BufNewFile,BufRead *.snippets setf snippets
    endif
    call UltiSnips_FileTypeChanged()
  endif
  nnoremap <f10> :call UltiSnips_ListSnippets()<cr>
endfunction
nnoremap <f10> :call LoadUltisnips()<cr>:call UltiSnips_ListSnippets()<CR>
inoremap <f10> <esc>:call LoadUltisnips()<cr>a<c-r>=UltiSnips_ExpandSnippet()<cr>

Revision history for this message
Jorge (skeept) said :
#3

Thanks SirVer, that solved my question.