Reputation: 315
I want to create some snippets when writting c++.
for example:
create a file, cpp.snippets.
priority -1
snippet exam
This is an example!
endsnippet
and put it in ~/.vim/my-snippets/snippets/.
then, add following statement in ~/.vimrc:
set runtimepath+=~/.vim/my-snippets/
let g:UltiSnipsSnippetsDir='~/.vim/my-snippets/'
let g:UltiSnipsSnippetDirectories=["snippets"]
But it not work, how can i fix it ?
Upvotes: 12
Views: 17935
Reputation: 3462
If you are using the sirver/ultisnips
plugin (UltiSnips) the correct way to do this is simply run the :UltiSnipsEdit
command which opens up a custom snippets file for the current language / filetype.
Upvotes: 15
Reputation: 1976
UltiSnips plugin includes detailed documentation. Have you read the following help page?
:help UltiSnips-snippet-search-path
Update:
One of the things that was obvious when I read that help section was that in UltiSnips the name "snippets" can't be used in g:UltiSnipsSnippetDirectories
because it is reserved for snipMate compatible snippets. This does not happen in the link shared in the comment below, where the name "my-snippets" is used instead.
I do not use UltiSnips, but from the documentation I would suggest the following approach:
g:UltiSnipsSnippetsDir
nor g:UltiSnipsSnippetDirectories
.runtimepath+=
configuration.~/.vim/my-snippets/UltiSnips
.Reasoning:
UltiSnips
directories under your runtime paths, so no configuration is required if this name is used.runtime
setting is required for personal snippets, this configuration is automatically maintained if a plugin manager is used.Upvotes: 16
Reputation: 3096
I had so much grief with this. Here is an answer for future reference for those of you who do not want to suffer headaches.
I have a shared .vimrc
served on a samba share. Both Windows gViM and ViM use this file.
I have a samba share mounted under L:
. Note that I actually had to use POSIX for the path, not Windows backslashes \
despite being a path for Windows.
if has('win32') || has('win64') "If gVim under Windows"
let g:UltiSnipsSnippetDirectories=["L:/.vim/custom_snippets"]
endif
My terminal opens xterm-256color
for more colors, but you could exchange that with xterm
. Here the path can expand ~
correctly, since this is the real home directory where my ``.vim` lives.
if $TERM == "xterm-256color"
let g:UltiSnipsSnippetDirectories=["~/.vim/custom_snippets"]
endif
You don't need any! The following changes are NOT necessary:
"let g:UltiSnipsSnippetDirectories=["custom_snippets"]
"let g:UltiSnipsSnippetsDir="~/.vim/snippets_custom/"
However, Putty does not pass the tab key or control key properly it seems, despite all paths working fine. I tested the paths with :UltiSnipsEdit
while in a file type environment set ft=tex
and it took me to ~/.vim/snippets_custom/tex.snippets
as it should (both in gvim on Windows and from my unix console).
Perhaps Useful for enabling in Putty
Upvotes: 1