nvim-snippy icon indicating copy to clipboard operation
nvim-snippy copied to clipboard

Expand a snippet inside another

Open tiagoprn opened this issue 3 years ago • 4 comments

Is it possible to expand a snippet inside another? E.g.:

snippet qtimestamp
	`strftime("%Y-%m-%dT%H:%M:%S")`-03:00

snippet qheader
	---
	created: qtimestamp
	modified: qtimestamp
	type: Journal
	---

On the example above, on the snippet "qheader", I would like to automatically expand the qtimestamp snippet on the "created" and "modified" fields.

tiagoprn avatar May 25 '22 10:05 tiagoprn

Hi. That kind of reference to another snippet from a snippet's body isn't possible, though I agree it would be handy sometimes. I'm not aware of any snippet engine that supports it.

dcampos avatar May 26 '22 23:05 dcampos

The snippets engine I used before, vim-vsnip, supports that: https://github.com/hrsh7th/vim-vsnip#features - it calls that feature "nested snippet expansion".

As a user I think that feature is awesome, but as a developer I have a feeling this may be not trivial to implement. :sweat_smile:

Nice to see you tagged this as an enhancement, I would be happy to test it if you decide to work on that, just mention me on this issue.

BTW, congrats for your work here! :rocket: I prefer your plugin because your snippets are much, much more cleaner than VSCode's style ones with all that JSON. :sunglasses:

tiagoprn avatar May 27 '22 09:05 tiagoprn

The snippets engine I used before, vim-vsnip, supports that: https://github.com/hrsh7th/vim-vsnip#features - it calls that feature "nested snippet expansion".

Interesting. I thought the "nested snippet expansion" referred to expanding a snippet from inside an already expanded snippet, which is also possible with Snippy—that is, you expand a snippet, type the trigger for another snippet, and expand it.

Does it mean Vsnip allows to automatically expand a snippet? Can you give an example?

dcampos avatar May 27 '22 15:05 dcampos

I guess at least for VS-Code style snippets, it does.

I had mine on that format before. Using the same example as the one I opened this issue with, when I triggered the qheader snippet, it already expanded the qtimestamp one. That got me impressed, and I started relying on that funcionality (maybe too much? :rofl:)

But I did not try it at the time with the snippets on the same format as snippy and vsnip support. So maybe that is particular to VSCode's JSON format? (which I do not intend to use due to parsing the JSON being much more prone to errors).

tiagoprn avatar May 27 '22 17:05 tiagoprn