5

I am using UltiSnips for my snippets. I have only used LaTeX snippets with UltiSnips, which I defined in a tex.snippets file inside of an UltiSnips directory in my runtimepath.

Now, I would like to write snippets for Python as well. How do I do it? Is there a particular name I have to give to the .snippets file? Is there a different syntax for Python snippets?

2 Answers 2

5

:UltiSnipsEdit will automatically open ultisnips for current filetype. From there you can see that it's supposed to be python.snippets.

3

UltiSnips uses a strategy similar to how Vim detects :h ftplugins. That is, it will look for the filenames that match the following pattern in your UltiSnips directory: ft.snippets, ft_*.snippets, or ft/*, where ft is replaced with your Vim filetype (python, c, etc.) and * matches any string including the empty string. A table from :h UltiSnips-how-snippets-are-loaded:

snippet filename         filetype ~
ruby.snippets            ruby
perl.snippets            perl
c.snippets               c
c_my.snippets            c
c/a                      c
c/b.snippets             c
all.snippets             all
all/a.snippets           all

So, to write snippets for the python filetype, you can use UltiSnips/python.snippets (or UltiSnips/python_classes.snippets, or UltiSnips/python/classes.snippets, for example).

All *.snippet files use the same syntax, regardless of filetype.

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.