3

By default my Ultisnips (or maybe it's Vim) associate .h files with C++ snippets.

I was about to ask how to make how to make Ultisnipps associate .h files with c types, but then I realized that my C snippets are valid for C++, so my question is how can I use common snippets for C and C++ ?

Thank you !

1 Answer 1

2

UltiSnips has the extends keyword. You pass a comma separated list of filetypes to it and it will load the snippets for those filetypes before the snippets in the file the keyword is used in.

Example:

extends c, obj-c

This way you can have a "cpp.snippets" file which "extends" your c filetype and obj-c type. The documentation doesn't mention cyclic extending but it will probably get in a loop and break something so don't do that. I'm pretty sure you can use a fake filetype so you can do something like this:
- create a snippet file called "cgeneral.snippets" which shouldn't get loaded by UltiSnips automatically
- create your "c.snippets" file
- add "extend cgeneral" at the top (can actually be anywhere in the file)
- repeat for "cpp.snippets"
Now you can have all general stuff in "cgeneral" and import that into your c.snippets file and your cpp one, too.

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.