0

I have been using the plugin called Ultisnips and it is great.

But I am looking for the following feature.

Suppose I have two files history.tex and geography.tex which I edit regularly.

I want to have snippets for each of them but I want them to be independent of each other. What I mean by this is that if I am working on history.tex, a snippet named samplesnip serves some purpose while when I am working on geography.tex the snippet named samplesnip serves a completely different purpose.

Right now what I have is a file named tex.snippets where all my snippets for tex files go. So I do not have the kind of flexibility that I want.

1
  • Really, the easiest way would be to slightly rename a snippet (or both) - if they are so specialized.
    – VanLaser
    Sep 8, 2015 at 11:00

1 Answer 1

3

You want to use UltiSnipsAddFiletypes. As the docs say:

The UltiSnipsAddFiletypes command allows for explicit merging of other snippet filetypes for the current buffer. For example, if you edit a .rst file but also want the Lua snippets to be available you can issue the command >

:UltiSnipsAddFiletypes rst.lua

To automatically set the filetype when you edit a file, add the following to your vimrc:

autocmd BufNewFile,BufRead history.tex UltiSnipsAddFiletypes history.tex

Note that as stated in :help 'filetype', vim natively supports the idea of dotted filetypes, so you could change the filetype to history.tex to do custom filetype plugins, syntax, and more.

1
  • An alternative solution would be to use python interpolation in your snippet, but I think the above is more in line with what you want.
    – Matt Boehm
    Sep 9, 2015 at 16:55

Your Answer

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

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