1

There are two python.snippets in vim-snippets folder:

debian@debian:~/.vim/bundle$ ls  vim-snippets/snippets | grep python
python.snippets
debian@debian:~/.vim/bundle$ ls  vim-snippets/UltiSnips | grep python
python.snippets
  1. Which one will be called when I type a abbreviation in vim?
  2. Which python.snippets should I write my customized snippets into?

They contains different grammar. It is as below in vim-snippets/snippets/python.snippets:

snippet if
    if ${1:condition}:
        ${0:${VISUAL}}

It is as below in vim-snippets/UltiSnips/python.snippets:

snippet ifee "If / Elif / Else" b
if ${1:condition}:
    ${2:${VISUAL:pass}}
elif ${3:condition}:
    ${4:pass}
else:
    ${5:pass}
endsnippet
  1. Which one is the correct grammar?

1 Answer 1

2

There are two formats of snippets that Ultisnips supports: (1) SnipMate snippets, and (2) UltiSnips snippets. Files containing SnipMate snippets (1) would go in the snippets directory, while files containing UltiSnips snippets (2) would go in the UltiSnips directory.

UltiSnips was designed to be a drop-in replacement for SnipMate (see :h UltiSnips-snipMate), enabling one to migrate over to UltiSnips with SnipMate snippets. In particular, support for SnipMate is controlled by the option g:UltiSnipsEnableSnipMate. If it is 1, both SnipMate and UltiSnips snippets will be used. And if it is 0, only Ultisnips snippets will be used.

As for your second question, you can use either, but note that their formats differ (snipmate format) (UltiSnips format). Personally, I would recommend the UltiSnips format. That is, place python_*.snippets in the UltiSnips directory. Actually, instead of vim-snippets/UltiSnips/python.snippets, you should use place the file in a custom directory , that is, .vim/UltiSnips/python.snippets. You should also read :h UltiSnips-how-snippets-are-loaded for more details of which filenames are supported.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.