Ultisnips: Ultisnips tab completion is not working.

Created on 9 Jun 2015  ·  48Comments  ·  Source: SirVer/ultisnips

I followed yours and Drew Neil's Screencast tutorial.
Somehow I'm not able to expand snippets with tab completion or by any other way.
However everything else seems fine. I get :UltiSnipsEdit commands and it opens a new snippet-file for that filetype. But by somehow I'm not able to get those snippets expanded in vim.
I'm using macvim version: 7.4.712.

Here is my full .vimrc file.

set nocompatible
"***************************** NeoBundleSetup ***********************
"NeoBundle Scripts-----------------------------
if has('vim_starting')
  if &compatible
    set nocompatible               " Be iMproved
  endif

  " Required:
  set runtimepath+=/Users/arpit/.vim/bundle/neobundle.vim/
endif

" Required:
call neobundle#begin(expand('/Users/arpit/.vim/bundle'))

" Let NeoBundle manage NeoBundle
" Required:
NeoBundleFetch 'Shougo/neobundle.vim'

" Add or remove your Bundles here:

NeoBundle 'AndrewRadev/splitjoin.vim'
NeoBundle 'marijnh/tern_for_vim'
NeoBundle 'Lokaltog/vim-easymotion'
NeoBundle 'Raimondi/delimitMate'
NeoBundle 'Shougo/neosnippet-snippets'
NeoBundle 'Shougo/neosnippet.vim'
NeoBundle 'Shougo/unite.vim'
NeoBundle 'SirVer/ultisnips'
NeoBundle 'amix/vim-zenroom2'
NeoBundle 'xolox/vim-misc'
NeoBundle 'xolox/vim-notes'
NeoBundle 'bling/vim-airline'
NeoBundle 'bling/vim-bufferline'
NeoBundle 'ctrlpvim/ctrlp.vim'
NeoBundle 'flazz/vim-colorschemes'
NeoBundle 'honza/vim-snippets'
NeoBundle 'junegunn/goyo.vim'
NeoBundle 'junegunn/vim-easy-align'
NeoBundle 'mattn/emmet-vim'
NeoBundle 'mattn/gist-vim', {'depends': 'mattn/webapi-vim'}
NeoBundle 'matze/vim-move'
NeoBundle 'powerline/powerline'
NeoBundle 'rking/ag.vim'
NeoBundle 'scrooloose/nerdtree'
NeoBundle 'ryanoasis/vim-webdevicons'
NeoBundle 'scrooloose/syntastic'
NeoBundle 'sjl/gundo.vim'
NeoBundle 'terryma/vim-multiple-cursors'
NeoBundle 'ryanoasis/vim-webdevicons'
NeoBundle 'tomtom/tcomment_vim'
NeoBundle 'tpope/vim-endwise'
NeoBundle 'tpope/vim-fugitive'
NeoBundle 'tpope/vim-rails'
NeoBundle 'tpope/vim-sensible'
NeoBundle 'tpope/vim-surround'
NeoBundle 'tpope/vim-vinegar'
NeoBundle 'will133/vim-dirdiff'
NeoBundle 'Valloric/YouCompleteMe', {
     \ 'build'      : {
        \ 'mac'     : './install.sh --clang-completer --system-libclang --omnisharp-completer',
        \ 'unix'    : './install.sh --clang-completer --system-libclang --omnisharp-completer',
        \ 'windows' : './install.sh --clang-completer --system-libclang --omnisharp-completer',
        \ 'cygwin'  : './install.sh --clang-completer --system-libclang --omnisharp-completer'
        \ }
     \ }
" Add or remove arguments to install.sh as necessary.
" Additional steps might be necessary for Windows, as always. ;)
let g:neobundle#install_process_timeout = 1500

NeoBundle 'Shougo/vimproc.vim', {
            \ 'build' : {
            \     'windows' : 'tools\\update-dll-mingw',
            \     'cygwin' : 'make -f make_cygwin.mak',
            \     'mac' : 'make -f make_mac.mak',
            \     'linux' : 'make',
            \     'unix' : 'gmake',
            \    },
            \ }
"NeoBundle 'Shougo/neocomplete.vim' <-- For this pluging I followed the github
"instructions and extracted(copy-passted) autoload,doc and plugin folder in
"~/.vim directory.



" If there are uninstalled bundles found on startup,
" this will conveniently prompt you to install them.
NeoBundleCheck
"


" You can specify revision/branch/tag.
NeoBundle 'Shougo/vimshell', { 'rev' : '3787e5' }

" Required:
call neobundle#end()

" Required:
filetype plugin indent on

"---------------------------- End NeoBundle Scripts -------------------------

"*********************** NeoBundleFinish ****************************
"
"
"
"
"=====[ Show help files in a new tab, plus add a shortcut for helpg]==============

let g:help_in_tabs = 1

nmap <silent> H  :let g:help_in_tabs = !g:help_in_tabs<CR>

"Only apply to .txt files...
augroup HelpInTabs
    autocmd!
        autocmd BufEnter  *.txt   call HelpInNewTab()
        augroup END

"Only apply to help files...
        function! HelpInNewTab ()
            if &buftype == 'help' && g:help_in_tabs
                    "Convert the help window to a tab...
                            execute "normal \<C-W>T"
                                endif
                                endfunction
"
"
"
"Settings for syntastic plugin from its README file
"set statusline+=%#warningmsg#
"set statusline+=%{SyntasticStatuslineFlag()}
"set statusline+=%*

"let g:syntastic_always_populate_loc_list = 1
"let g:syntastic_auto_loc_list = 1
"let g:syntastic_check_on_open = 1
"let g:syntastic_check_on_wq = 1
"

"Go to Normal mode quickly
imap jk <Esc>



"
"Set the Leader key as space
let mapleader = "\<Space>"
"Open Vimrc in new file. Use :edit for opening it in current tab.
nmap <leader>v :tabedit $MYVIMRC<CR>

"NERDTree Settings
nmap <leader>nt :NERDTreeToggle<CR>

"Set autoindent
set autoindent
"Set line numbers and relative line numbers -  at this point I think they are
"awesome
set number
set relativenumber

"syntax on
syntax on


"set the syntax on
syntax enable

"highlighting the searches
set hlsearch " CTRL-L / CTRL-R W
set incsearch"

" Turn on the mouse, since it doesn't play well with tmux anyway. This way I can
" scroll in the terminal
set mouse=a


" Set to auto read when a file is changed from the outside
set autoread

" Display unprintable chars
set list
set listchars=tab:▸\ ,extends:❯,precedes:❮,nbsp:␣
set showbreak=↪

" How many lines to scroll at a time, make scrolling appears faster
set scrolljump=3

" Case insensitive search
set ignorecase
set smartcase

" Don't show matching brackets
set noshowmatch

" Tab settings
set expandtab
set shiftwidth=2
set tabstop=2
set softtabstop=2
set smarttab



" Text display settings
set linebreak
set textwidth=80
set autoindent
set nowrap
set whichwrap+=h,l,<,>,[,]


"from https://github.com/Valloric/dotfiles/blob/master/vim/vimrc.vim
" with this, we can now type ",." to exit out of insert mode
" if we really wanted to type ",.", then just type one char, wait half a sec,
" type another
inoremap ,. <Esc>
vnoremap ,. <Esc>



"from https://github.com/Valloric/dotfiles/blob/master/vim/vimrc.vim
"let g:airline_powerline_fonts = 1

"from https://github.com/Valloric/dotfiles/blob/master/vim/vimrc.vim
" key bindings for quickly moving between windows
" h left, l right, k up, j down
noremap <leader>h <c-w>h
noremap <leader>l <c-w>l
noremap <leader>k <c-w>k
noremap <leader>j <c-w>j









"Type <Space>w to save file (a lot faster than :w<Enter>):
noremap <Leader>w :w<CR>

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

and here is the snippet I tried for markdown files.

snippet fm

---
title: $1
date: $2
tags: $3

---
$0
endsnippet

Most helpful comment

I had trouble getting everything to work as expected with <tab> as well. Following the advice from this StackOverflow answer did the trick for me:

" if you use Vundle, load plugins:
Bundle 'ervandew/supertab'
Bundle 'Valloric/YouCompleteMe'
Bundle 'SirVer/ultisnips'

" make YCM compatible with UltiSnips (using supertab)
let g:ycm_key_list_select_completion = ['<C-n>', '<Down>']
let g:ycm_key_list_previous_completion = ['<C-p>', '<Up>']
let g:SuperTabDefaultCompletionType = '<C-n>'

" better key bindings for UltiSnipsExpandTrigger
let g:UltiSnipsExpandTrigger = "<tab>"
let g:UltiSnipsJumpForwardTrigger = "<tab>"
let g:UltiSnipsJumpBackwardTrigger = "<s-tab>"

All 48 comments

I removed neosnippets from my vimrc file but the problem still persists.

Can you check :verbose imap <tab>?

Same problem using Vim 7.4 in Mac

When I run :verbose imap <tab> I see

i  <Tab>       * pumvisible() ? "\<C-N>" : "\<Tab>"
        Last set from ~/.vim/bundle/YouCompleteMe/autoload/youcompleteme.vim

But I have this setting in my vimrc

let g:UltiSnipsExpandTrigger="<tab>"

The plugin doesn't work when YouCompleteMe isn't installed either.

Any ideas?

After further investigation I have found

  • The plugin picks up snippets from inside all.snippets but no others. So I have javascript.snippets inside the ~/.vim/bundle/vim-snippets/Ultisnips directory but when I open app.js (with filetype javascript) it doesn't find the javascript snippets.
  • When I select a snippet from all.snippets after a trigger (for example lorem) it doesn't expand the snippet.
  • If I type UltiSnipsEdit it opens up an empty file at ~/.vim/Ultisnips/all.snippets.
  • When I move the UltiSnips directory from ~/.vim/bundles/vim-snippets to ~/.vim it still only picks up snippets from all.snippets.
  • If I type UltiSnipsEdit after the move it opens up the ~/.vim/Ultisnips/all.snippets and this time there is content because there is an existing file there.
  • If I add let g:UltiSnipsSnippetDirectories="/Users/john/.vim/bundle/vim-snippets/UltiSnips" it doesn't change anything.
  • If I add let g:UltiSnipsSnippetDirectories="UltiSnips" it doesn't change anything.

I removed the YouCompleteMe plugin after seeing

" Trigger configuration. Do not use if you use https://github.com/Valloric/YouCompleteMe.

Now there is no autocomplete at all again.

When I run verbose imap <tab> I see

i  <Tab>       * <C-R>=UltiSnips#ExpandSnippet()<CR>
    Last set from ~/.vim/bundle/ultisnips/autoload/UltiSnips/map_keys.vim

Okay, finally discovered that it doesn't seem to be setting the filetype.

When I set UltiSnipsAddFiletypes manually it finds the snippets.

At present I just have a few autocmds in my vimrc

au FileType javascript :UltiSnipsAddFiletypes javascript

followed the same guidelines as @whatsthebeef has followed.
Still I don't get any snippet-completion :(

I had trouble getting everything to work as expected with <tab> as well. Following the advice from this StackOverflow answer did the trick for me:

" if you use Vundle, load plugins:
Bundle 'ervandew/supertab'
Bundle 'Valloric/YouCompleteMe'
Bundle 'SirVer/ultisnips'

" make YCM compatible with UltiSnips (using supertab)
let g:ycm_key_list_select_completion = ['<C-n>', '<Down>']
let g:ycm_key_list_previous_completion = ['<C-p>', '<Up>']
let g:SuperTabDefaultCompletionType = '<C-n>'

" better key bindings for UltiSnipsExpandTrigger
let g:UltiSnipsExpandTrigger = "<tab>"
let g:UltiSnipsJumpForwardTrigger = "<tab>"
let g:UltiSnipsJumpBackwardTrigger = "<s-tab>"

You are missing

filetype plugin indent on

and therefore your ftdetect/UltiSnips.vim file is not sourced. See https://github.com/Shougo/neobundle.vim again, the line is marked 'required' directly after neobundle end.

Closing, as I think that fixes the issue. Will reopen if that is not the case.

Is there any way to add all filetypes availables automatically whitout autocmds?

This usually indicates that your vundle/plugin manager setup is faulty. Please post your entire vimrc.

Am 02.08.2015 um 10:01 schrieb Absalón Valdés Ormeño [email protected]:

Is there any way to add all filetypes availables automatically whitout autocmds?


Reply to this email directly or view it on GitHub.

You are right. I was missing filetype off before Vundle setup. Sorry for that. Thanks.

I stopped using vim because in YCM i can use TAB to cycle on completions but there is no way to expand snippet by tab or even by "Enter". So I switched to Sublime 3 - its engine is IMO superior to VIM.

How to expand snippet using Enter https://github.com/Valloric/YouCompleteMe/issues/420#issuecomment-55940039

@Behinder you stopped using vim due to a minor configuration issue then adopted a less configurable editor in reaction? Baffled.....

@ohjames i wouldn't call this MINOR issue if it's frustrating. And Sublime is not at all less configurable, period.

I moved out of my house because the blinds in the loft were too dark for my liking. So I moved into a house with no windows - its darkness is, IMO, superior to having to look at dark shabby blinds.

this bug tracker is not the place for these sorts of discussions. Please cease the off topic banter.

Am 11.12.2015 um 15:02 schrieb Mr Friend [email protected]:

I moved out of my house because the blinds in the loft were too dark for my liking. So instead I moved into a house with no windows - its darkness is, IMO, superior to having to look at dark shabby blinds.


Reply to this email directly or view it on GitHub.

@SirVer, what is the solution of this issues. I'm having the same problem. I can cycle through snippets with , but I can't figure out how to expand them :( Tia, Rad

@nad2000 check out the comment I linked to this thread.

I am also having this issue. lorem<tab> works, but any snippets from other files do not.

Fixed my issue:
I was trying to use angular snippets. They need to be manually loaded:

  1. make a directory in .vim called ftplugin
  2. create a file called javascript.vim
  3. Put :UltiSnipsAddFiletypes javascript-angular in the file.

Incase anyone is as silly as me, I went through everything everyone suggested:

let g:UltiSnipsExpandTrigger="<tab>"
let g:UltiSnipsJumpForwardTrigger="<tab>"
let g:UltiSnipsJumpBackwardTrigger="<s-tab>"

filetype plugin indent on

And so forth, angered that after :source ~/.vimrc nothing was fixed, I had to reload MacVim and now it works flawlessly.

I guys,

I had the same issue, in my case the problem was a conflict between Ultisnips and Rykka/riv.vim plugins. After removing riv.vim the Tab completion works as expected with

let g:UltiSnipsExpandTrigger="<tab>"

After this change, the position of the line

filetype plugin indent on

respect to the let g:Ultisnips* lines makes no difference.

@elchinot7 You can use both Ultisnips and Rykka/riv.vim. You only need to set
let g:riv_ignored_imaps = "<Tab>,<S-Tab>"in order to use Tab as expected.

I have the same tab expand problem. I am running MacVim 7.4.2 and using the vim-plug manager. When I press <tab> a tab is inserted. Here is my .vimrc:

call plug#begin('~/.vim/plugged')
Plug 'SirVer/ultisnips'
call plug#end()

let g:UltiSnipsExpandTrigger="<tab>"
let g:UltiSnipsJumpForwardTrigger="<tab>"
let g:UltiSnipsJumpBackwardTrigger="<s-tab>"
let g:UltiSnipsEditSplit="vertical"

I can run UltiSnipsEdit and this is my html.snippets file:

snippet t "test div" 
<div>
  test
</div>
endsnippet

When I edit an html file, it is syntax color coded, so I think the filetype is recognized. How do I find what is wrong?

---- an addition ---
I thought it might help to have the output of :map; here it is:

s  <C-H>       * <C-G>c
        Last set from ~/.vim/plugged/ultisnips/autoload/UltiSnips/map_keys.vim
x  <Tab>       * :call UltiSnips#SaveLastVisualSelection()<CR>gvs
        Last set from ~/.vim/plugged/ultisnips/autoload/UltiSnips/map_keys.vim
s  <Tab>       * <Esc>:call UltiSnips#ExpandSnippetOrJump()<CR>
        Last set from ~/.vim/plugged/ultisnips/autoload/UltiSnips/map_keys.vim
s  <C-R>       * <C-G>"_c<C-R>
        Last set from ~/.vim/plugged/ultisnips/autoload/UltiSnips/map_keys.vim
n  <C-W><C-O>    <C-W>o
        Last set from ~/.vim/plugin/project.vim
n  <C-W>o        <Plug>ProjectOnly
        Last set from ~/.vim/plugin/project.vim
   \c            :echo g:colors_name<CR>
        Last set from ~/.vim/plugin/ScrollColor.vim
   \p            :CP<CR>
        Last set from ~/.vim/plugin/ScrollColor.vim
   \n            :CN<CR>
        Last set from ~/.vim/plugin/ScrollColor.vim
n  gx            <Plug>NetrwBrowseX
        Last set from /Applications/MacVim.app/Contents/Resources/vim/runtime/plugin/netrwPlugin.vim
n  <Plug>ProjectOnly & :call <SNR>17_DoProjectOnly()<CR>
        Last set from ~/.vim/plugin/project.vim
n  <Plug>NetrwBrowseX * :call netrw#NetrwBrowseX(expand("<cWORD>"),0)<CR>
        Last set from /Applications/MacVim.app/Contents/Resources/vim/runtime/plugin/netrwPlugin.vim
s  <Del>       * <C-G>c
        Last set from ~/.vim/plugged/ultisnips/autoload/UltiSnips/map_keys.vim
s  <BS>        * <C-G>c
        Last set from ~/.vim/plugged/ultisnips/autoload/UltiSnips/map_keys.vim
s  <C-Tab>     * <Esc>:call UltiSnips#ListSnippets()<CR>
        Last set from ~/.vim/plugged/ultisnips/autoload/UltiSnips/map_keys.vim
n  <Plug>ToggleProject & :call <SNR>17_DoToggleProject()<CR>
        Last set from ~/.vim/plugin/project.vim
x  <BS>          "-d

@wesmat: Where do you store your html.snippets file?

I am using the default location. When I edit it says:

"~/UltiSnips/html.snippets"

Hmm, but that doesn't look right - shouldn't that be inside ~/.vim?
When I search for html.snippets from my home dir I see:

$ find . -name html.snippets
./.vim/plugged/vim-snippets/snippets/html.snippets
./.vim/plugged/vim-snippets/UltiSnips/html.snippets
./UltiSnips/html.snippets

I looked in these other two files and attempted to use a snippet defined in them, but they don't work either.

I am fairly sure that vim-plug did not properly install ultisnips. How do I check it or should I remove and do a manual install - which means I need manual install instructions.

I'm also having the same problem. UltiSnips suddenly stopped expanding snippets.

Running :verbose imap <tab> (suggested by @SirVer) gives me the following output:

i  <Tab>       * <C-R>=UltiSnips#ExpandSnippetOrJump()<CR>
        Last set from ~/.vim/bundle/ultisnips/autoload/UltiSnips/map_keys.vim

I've enabled all the config options suggested by @whatsthebeef and @mmwtsn:

let g:UltiSnipsExpandTrigger='<tab>'
let g:UltiSnipsJumpForwardTrigger='<tab>'
let g:UltiSnipsJumpBackwardTrigger='<s-tab>'
let g:UltiSnipsEditSplit='vertical'

(full .vimrc here)

I use Vundle as my plugin manager.

Any ideas?


Update

It seems to be an issue with Neovim exclusively. Not really sure what's happening.

@rafaelrinaldi: Unfortunately, neovim is not supported by me, because it's too unstable.

@seletskiy After keeping up with the project for a while I'll have to agree with you. I just switched back to Vim (the latest build) and everything is working perfectly.

Thanks.

UltiSnips suddenly stopped expanding snippets

@rafaelrinaldi It was working in an earlier Neovim version? If so, can you give a rough idea of which? Were you compiling from HEAD or using a packaged version (0.1.2, 0.1.3, ...)

@justinmk Yeah, I never had the issue before. I first noticed it after upgrading neovim through homebrew (not HEAD, the regular release).

@rafaelrinaldi Did you also update the neovim python module?

pip  install --upgrade neovim

(or pip2/pip3 depending on your distro, etc...)

@justinmk Yes, I did. I usually do this after I upgrade Neovim (people always recommend doing this before submitting an issue, etc).

While I cannot speak for rafaelrlnaldi, I just did a test with neovim 0.14 and init.vim that contains _only_ the following:

syntax on
call plug#begin('~/.config/nvim/plugged')
Plug 'SirVer/ultisnips'
call plug#end()

And that did actually work for me.

@rafaelrinaldi Can you please try the following? Update your plugin manager to the latest version (I use vim-plug), clear out your entire plugins/bundle directory, reinstall all the plugins (with vim-plug that would be :PlugInstall), and rebuild YouCompleteMe if you use it.

UltiSnips started working for me again after I did that. Please let me know if it starts working for you after you do that.

@duganchen Thanks for helping out. I did a fresh install and now it seems to be working fine!

confirmed. It works on fresh install

executing :verbose imap <tab> in neovim
I got:

i  <Tab>         <Plug>SuperTabForward
    Last set from ~/.config/nvim/plugged/supertab/plugin/supertab.vim

In vim I got:

i  <Tab>       * <C-R>=UltiSnips#ExpandSnippetOrJump()<CR>
    Last set from ~/.vim/bundle/ultisnips/autoload/UltiSnips/map_keys.vim

The plugin loading orders are different for vbundle and vim-plug

Based on https://github.com/junegunn/vim-plug/issues/365,
the plugin order of vim-plug is based on the order Plug command. If Plug 'supertab' is executed before Plug 'Ultisnips', the problem will be solved.

For someone who cannot get UltiSnips working and stumble upon this issue, here are what I did to finally get it working (I didn't install YouCompleteMe)

Initially, I set the two UltiSnips options as these

let g:UltiSnipsSnippetsDir='/Users/[user_name]/.vim/mysnippets'
let g:UltiSnipsSnippetDirectories='/Users/[user_name]/.vim/mysnippets'

Later I found this in UltiSnips help page (:h UltiSnips-snippet-search-path)

UltiSnips will search each 'runtimepath' directory for the subdirectory names
defined in g:UltiSnipsSnippetDirectories in the order they are defined.

And the example the help page provides is

let g:UltiSnipsSnippetDirectories=["UltiSnips"]

Thus, I change my configuration to these and it works!

let g:UltiSnipsSnippetsDir='/Users/[user_name]/.vim/mysnippets'
let g:UltiSnipsSnippetDirectories=["mysnippets"]

Although this is closed, I just wanted to add a solution since I ran into a similar issue. What fixed it for me was adding:

" Add home directory to runtimepath
set rtp^=$HOME

to the bottom of my .vimrc (or rather init.vim). This made UltiSnips work with a (default?) ~/UltiSnips directory. My main issue was that manually added snippets were not included.

It's still not working for me, at all.

My snippets are in ~/dotfiles/vim-snippets/. I reset my .vimrc to this, but it still doesn't work.

syntax on
filetype plugin indent on

call plug#begin('~/.vim/plugged')

Plug 'SirVer/ultisnips'
Plug 'honza/vim-snippets'

call plug#end()

let UltiSnipsExpandTrigger = "<tab>"
let UltiSnipsListSnippets = "<c-tab>"
let UltiSnipsJumpForwardTrigger = "<c-j>"
let UltiSnipsJumpBackwardTrigger = "<c-k>"

let UltiSnipsEditSplit = "vertical"
let UltiSnipsUsePythonVersion = 3
let UltiSnipsSnippetsDir = "~/dotfiles/vim-snippets/"
let UltiSnipsSnippetsDirectories = ["vim-snippets"]
let UltiSnipsEnabledSnipMate = 0

As you can see, I use vim-plug.

Runtime path:

runtimepath=~/.vim,~/.vim/plugged/ultisnips/,~/.vim/plugged/vim-snippets/,/var/lib/vim/addons,/usr/share/vim/vimfiles,/usr/share/vim/vim80,/usr/share/vim/vimfiles/after,/var/lib/vim/addons/after,~/.vim/plugged/ultisnips/after,~/.vim/after

I'm on Windows 10 bash. I also tested with cygwin (mintty) previously, it wasn't working either.

What am I doing wrong?

I solved this by changing

let g:UltiSnipsSnippetsDir="~/config-files/ultisnips/"
let g:UltiSnipsSnippetDirectories=["ultisnips"]

to

let g:UltiSnipsSnippetsDir="~/.vim/ultisnips"
let g:UltiSnipsSnippetDirectories=["ultisnips"]

and moving my snippets into ~/.vim/ultisnips.

I suspected that the issue was that ~/config-files/ultisnips wasn't in my runtimepath, and it looks like that was correct.

You don't have to move your snippets into the .vim dir by the way. I'm still keeping my ~/config-files/ultisnips by creating a symlink to it from ~/.vim/ultisnips:

ln -s ~/config-files/ultisnips ~/.vim/ultisnips

Environment

  • gVim 8.0
  • Windows 8.1
  • UltiSnips commit 423f264e753cec260b4f14455126e6db7ba429af

The issue is that tab trigger works fine when I use default snippets from honza/vim-snippets repo e.g. date, lorem. But if I use :UltiSnipsEdit to create a private snippet, then tab trigger doesn't work for the private snippet. This is what I found out.

Cause

By default, the variable g:UltiSnipsSnippetsDir (i.e. directory in which private snippets are saved) is not set. The default behavior when that variable is not set seems to be to save private snippets in UltiSnips directory in the current working directory (maybe the directory name depends on your g:UltiSnipsSnippetDirectories value?).

This is bad because UltiSnips looks for snippets in runtimepath directories (see :h UltiSnips-snippet-search-path) and chances are your private snippets would not be saved in those directories with the default settings.

Solution

Set g:UltiSnipsSnippetsDir to somewhere in the runtimepath in your vimrc. In my case

let g:UltiSnipsSnippetsDir = "~/vimfiles/UltiSnips"
  • Replace vimfiles above with .vim if using Linux.
  • Replace UltiSnips above with the value you use for g:UltiSnipsSnippetDirectories.

I feel like this should be mentioned in the Quickstart section of README.md

For someone who cannot get UltiSnips working and stumble upon this issue, here are what I did to finally get it working (I didn't install YouCompleteMe)

Initially, I set the two UltiSnips options as these

let g:UltiSnipsSnippetsDir='/Users/[user_name]/.vim/mysnippets'
let g:UltiSnipsSnippetDirectories='/Users/[user_name]/.vim/mysnippets'

Later I found this in UltiSnips help page (:h UltiSnips-snippet-search-path)

UltiSnips will search each 'runtimepath' directory for the subdirectory names
defined in g:UltiSnipsSnippetDirectories in the order they are defined.

And the example the help page provides is

let g:UltiSnipsSnippetDirectories=["UltiSnips"]

Thus, I change my configuration to these and it works!

let g:UltiSnipsSnippetsDir='/Users/[user_name]/.vim/mysnippets'
let g:UltiSnipsSnippetDirectories=["mysnippets"]

Stuck for 3 hours you just save my life

I'm using Neovim, and struggled with this problem for a few hours. Finally, I decided to check that my ~/.vim directory actually is in the runtime path. It was not. After moving my snippet folder to ~/.config/nvim instead, it started to work! You can check which paths are included, like this set runtimepath?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

MikeDacre picture MikeDacre  ·  3Comments

Alex-Canales picture Alex-Canales  ·  4Comments

zuntik picture zuntik  ·  7Comments

ghost picture ghost  ·  8Comments

codybuell picture codybuell  ·  4Comments