I am using Neovim with UltiSnips and deoplete as my completion engine. The following settings are tested both on Windows 10 (nvim version 0.3.4 )and Linux (CentOS 7, nvim version 0.4.0).
The documentation of UltiSnips has explained how the snippets are searched (see :h UltiSnips-how-snippets-are-loaded
). But it is still not crystal clear how to configure so that our custom snippets can be found by UltiSnips.
From the documentation of UltiSnips:
UltiSnips will search each 'runtimepath' directory for the subdirectory names defined in g:UltiSnipsSnippetDirectories in the order they are defined. For example, if you keep your snippets in ~/.vim/mycoolsnippets
and you want to make use of the UltiSnips snippets that come with other plugins, add the following to your vimrc file.
let g:UltiSnipsSnippetDirectories=["UltiSnips", "mycoolsnippets"]
The description above is both informative and confusing because it is written for Vim users, not Neovim users. As a result, if you follow the above example, you will find that the custom snippets are not available for auto-completion.
In the following, I will write what is working for Neovim.
First, open nvim and use the command :echo &runtimepath
. This command will print all the runtime paths that Neovim searches. According to the documentaion, your custom snippets directory should be put under one of these runtime paths. On my Windows machine, the output is like (the full output is omitted for brevity):
C:\Users\Administrator\AppData\Local\nvim,C:\Users\Administrator\AppData\Local\nvim\plugged\deoplete.nvim,C:\Users\Administrator\AppData\Local\nvim\plugged\deoplete-jedi,C:\Users\Administrator\AppData\Local\nvim\plugged\neco-vim,.....
On my Linux machine, the output is like (the full output is omitted):
/home/haojiedong/.config/nvim,/home/haojiedong/.local/share/nvim/plugged/deoplete.nvim/,/home/haojiedong/.local/share/nvim/plugged/deoplete-jedi/,/home/haojiedong/.local/share/nvim/plugged/jedi-vim/,.....
Different runtime paths are separated by a comma. The steps of configuring custom snippets are the same for both Windows and Linux. So in the following part, I will only focus on Linux since it is more popular.
One of the runtime paths on Linux is /home/haojiedong/.config/nvim
. We choose this directory and create a folder named my_snippets
. Then we create a file named markdown.snippets
under folder my_snippets
. Add the following snippet to markdown.snippets
:
snippet kbd "Keyboard tag"
<kbd>${1:KEY}</kbd> $0
endsnippet
This will create a snippet named kbd
for markdown filetype.
In the third step, we add the following setting to init.vim
:
" `my_snippets` is the directory we created before
let g:UltiSnipsSnippetDirectories=["UltiSnips", "my_snippets"]
Now, open a markdown file and start typing kbd
and you should be able to see the kbd
autocomplete item:

The completion engine I am using is deoplete and US
means that this completion item is from UltiSnips.