# Need snippets, we got snippets

**URL:** <https://discuss.kakoune.com/t/need-snippets-we-got-snippets/42>\
**Category:** Plugins\
**Created:** [September 15, 2018, 1:55am UTC](https://discuss.kakoune.com/t/need-snippets-we-got-snippets/42 "2018-09-15T01:55:29Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![robertmeta](https://discuss.kakoune.com/user_avatar/discuss.kakoune.com/robertmeta/32/833_2.png) [@robertmeta](https://discuss.kakoune.com/u/robertmeta)\
**Post date:** [September 15, 2018, 1:55am UTC](https://discuss.kakoune.com/t/need-snippets-we-got-snippets/42/1 "2018-09-15T01:55:29Z")

</div>

- [https://github.com/alexherbo2/snippets.kak](https://github.com/alexherbo2/snippets.kak)

Great simple plugin that stays out of your way, but does exactly as required.

---

<div class="post-metadata">

**Author:** ![JJK96](https://discuss.kakoune.com/user_avatar/discuss.kakoune.com/jjk96/32/305_2.png) [@JJK96](https://discuss.kakoune.com/u/JJK96)\
**Post date:** [September 16, 2018, 4:44pm UTC](https://discuss.kakoune.com/t/need-snippets-we-got-snippets/42/2 "2018-09-16T16:44:38Z")

</div>

Another snippet plugin that can jump to holes and can work together with [emmet snippets](https://github.com/Delapouite/emmet-cli) in additiont to expanding user-defined snippets: [https://github.com/JJK96/kakoune-snippets](https://github.com/JJK96/kakoune-snippets)

It uses the same snippet pattern as the [language server protocol](https://microsoft.github.io/language-server-protocol/specification) so it can be used to expand snippets provided by [kak-lsp](https://github.com/ul/kak-lsp) as soon as that has support for outputting snippets.

---

<div class="post-metadata">

**Author:** ![robertmeta](https://discuss.kakoune.com/user_avatar/discuss.kakoune.com/robertmeta/32/833_2.png) [@robertmeta](https://discuss.kakoune.com/u/robertmeta)\
**Post date:** [September 16, 2018, 5:14pm UTC](https://discuss.kakoune.com/t/need-snippets-we-got-snippets/42/3 "2018-09-16T17:14:27Z")

</div>

Oh, this is very neat, do you keep your fork of emmet-cli up to date with the upstream?

---

<div class="post-metadata">

**Author:** ![JJK96](https://discuss.kakoune.com/user_avatar/discuss.kakoune.com/jjk96/32/305_2.png) [@JJK96](https://discuss.kakoune.com/u/JJK96)\
**Post date:** [September 16, 2018, 7:43pm UTC](https://discuss.kakoune.com/t/need-snippets-we-got-snippets/42/4 "2018-09-16T19:43:58Z")

</div>

I do intend to keep it up to date with emmet-cli, I might keep it up to date with emmet-io if the maintainer of emmet-cli does not. I am not actively keeping track of changes with emmet-io but if I notice it breaking I will fix it.

---

<div class="post-metadata">

**Author:** ![Screwtapello](https://discuss.kakoune.com/user_avatar/discuss.kakoune.com/screwtapello/32/12_2.png) [@Screwtapello](https://discuss.kakoune.com/u/Screwtapello)\
**Post date:** [September 17, 2018, 12:25am UTC](https://discuss.kakoune.com/t/need-snippets-we-got-snippets/42/5 "2018-09-17T00:25:34Z")

</div>

> [@JJK96](#):
>
> It uses the same snippet pattern as the [language server protocol](https://microsoft.github.io/language-server-protocol/specification) so it can be used to expand snippets provided by [kak-lsp](https://github.com/ul/kak-lsp) as soon as that has support for outputting snippets.

I recall somebody in #kakoune mentioning that some language server was using snippet-syntax in ordinary completions, so it sounds like your plugin is _already_ useful.

I see that snippets depend on Python 3 and a YAML plugin, which probably isn’t too difficult to setup in general, but might be a bit heavyweight for some tastes. Have you considered just having a snippets directory, where the filename is the snippet abbreviation and the file’s content is the snippet body?

---

<div class="post-metadata">

**Author:** ![JJK96](https://discuss.kakoune.com/user_avatar/discuss.kakoune.com/jjk96/32/305_2.png) [@JJK96](https://discuss.kakoune.com/u/JJK96)\
**Post date:** [September 22, 2018, 5:02pm UTC](https://discuss.kakoune.com/t/need-snippets-we-got-snippets/42/6 "2018-09-22T17:02:49Z")

</div>

I have not considered it yet. I think I prefer having all snippets in the same file instead of having multiple files.  
Dependency on python is not a problem IMO, it is usually present on an arbitrary linux system. I can consider just manually parsing the file instead of using yaml.

---

<div class="post-metadata">

**Author:** ![TeddyDD](https://discuss.kakoune.com/user_avatar/discuss.kakoune.com/teddydd/32/21_2.png) [@TeddyDD](https://discuss.kakoune.com/u/TeddyDD)\
**Post date:** [September 22, 2018, 8:07pm UTC](https://discuss.kakoune.com/t/need-snippets-we-got-snippets/42/7 "2018-09-22T20:07:46Z")

</div>

Do you keep snippets for all languages in one file? Personally I’d prefer to split snippets per language.

---

<div class="post-metadata">

**Author:** ![JJK96](https://discuss.kakoune.com/user_avatar/discuss.kakoune.com/jjk96/32/305_2.png) [@JJK96](https://discuss.kakoune.com/u/JJK96)\
**Post date:** [September 22, 2018, 8:34pm UTC](https://discuss.kakoune.com/t/need-snippets-we-got-snippets/42/8 "2018-09-22T20:34:03Z")

</div>

I don’t have that much snippets yet, but splitting them per language seems reasonable. In addition, a different file could be loaded for a different language. Maybe the snippets should be stored in a kakoune option as in the first plugin of this thread. I will look into that.

---

<div class="post-metadata">

**Author:** ![JJK96](https://discuss.kakoune.com/user_avatar/discuss.kakoune.com/jjk96/32/305_2.png) [@JJK96](https://discuss.kakoune.com/u/JJK96)\
**Post date:** [September 23, 2018, 2:23pm UTC](https://discuss.kakoune.com/t/need-snippets-we-got-snippets/42/9 "2018-09-23T14:23:57Z")

</div>

I adapted the `snippet_files` option to be str-list now instead of str. So it can hold a list of snippet files.  
I also adapted the python program to read from multiple files now.

This option can also be adapted or overwritten per filetype using hooks.

I think storing the snippets in files is better than in a kakoune option afterall since this way means that the snippets refresh live when updated.

---

<div class="post-metadata">

**Author:** ![robertmeta](https://discuss.kakoune.com/user_avatar/discuss.kakoune.com/robertmeta/32/833_2.png) [@robertmeta](https://discuss.kakoune.com/u/robertmeta)\
**Post date:** [September 23, 2018, 10:12pm UTC](https://discuss.kakoune.com/t/need-snippets-we-got-snippets/42/10 "2018-09-23T22:12:10Z")

</div>

Nice, I think that is a huge improvement.

---

<div class="post-metadata">

**Author:** ![andreyorst](https://discuss.kakoune.com/user_avatar/discuss.kakoune.com/andreyorst/32/29_2.png) [@andreyorst](https://discuss.kakoune.com/u/andreyorst)\
**Post date:** [September 25, 2018, 2:02pm UTC](https://discuss.kakoune.com/t/need-snippets-we-got-snippets/42/11 "2018-09-25T14:02:36Z")

</div>

> [GitHub - alexherbo2/snippet.kak: Snippets integration for Kakoune](https://github.com/alexherbo2/snippets.kak)

Yeah, however such snippets are just skeleton files that are being triggered on certain keywords. Real snippets managers feature real-time mirroring, nested placeholders, placeholders with scriptable behavior, visual placeholders, that can yank text and put it somewhere inside next snippet, placeholders with choices, where you’re prompted with the list of possible values, and are free to select one or replace it with your own.

As example of scriptable behavior, my snippet plugin for Vim has C++ class snippet, that can detect current file’s name, and create include guard with this name uppercase, and class named against filename, but in lowercase:  
 ![SimpleSnippets.vim](https://discuss.kakoune.com/uploads/default/original/1X/9a3abd510cb56e2ef32b999b641442c254ed42c1.gif)  
Or for example in UltiSnips vim plugin there are markdown snippets, that have variable length, and can adopt to the length of previous line.

Because today language servers are ready to use in most editors, I think that good snippet manager should be compatible with LSP snippets: [language-server-protocol/snippetSyntax.md at main · microsoft/language-server-protocol · GitHub](https://github.com/Microsoft/language-server-protocol/blob/master/snippetSyntax.md)

I kinda miss those features and planning to start working on implementation of UltiSnips like plugin for kakoune when I finish with plugin manager, and fzf. However I’m not sure that I’ll be able to do such complicated plugin in shell script.

---

<div class="post-metadata">

**Author:** ![TeddyDD](https://discuss.kakoune.com/user_avatar/discuss.kakoune.com/teddydd/32/21_2.png) [@TeddyDD](https://discuss.kakoune.com/u/TeddyDD)\
**Post date:** [September 26, 2018, 10:09am UTC](https://discuss.kakoune.com/t/need-snippets-we-got-snippets/42/12 "2018-09-26T10:09:57Z")

</div>

I wouldn’t even try to do this in shell. Shell is fine as glue, or for simple scripts but it fails miserably for complicated programs.

---

<div class="post-metadata">

**Author:** ![andreyorst](https://discuss.kakoune.com/user_avatar/discuss.kakoune.com/andreyorst/32/29_2.png) [@andreyorst](https://discuss.kakoune.com/u/andreyorst)\
**Post date:** [September 26, 2018, 2:56pm UTC](https://discuss.kakoune.com/t/need-snippets-we-got-snippets/42/13 "2018-09-26T14:56:05Z")

</div>

> [@TeddyDD](#):
>
> Shell is fine as glue, or for simple scripts but it fails miserably for complicated programs.

If only you saw what I’ve saw in viml… 🙂

---

<div class="post-metadata">

**Author:** ![andreyorst](https://discuss.kakoune.com/user_avatar/discuss.kakoune.com/andreyorst/32/29_2.png) [@andreyorst](https://discuss.kakoune.com/u/andreyorst)\
**Post date:** [November 27, 2018, 12:28pm UTC](https://discuss.kakoune.com/t/need-snippets-we-got-snippets/42/14 "2018-11-27T12:28:53Z")

</div>

I’ve saw [this plugin](https://github.com/occivink/kakoune-phantom-selection) and thought that such technic can be used to create snippets for kakoune with placeholders, transformations, and other features of modern snippet managers like UltiSnips (vim) or yasnippet (emacs).

Simply by parsing a snippet and then putting a parsed text to file, one could store placeholder information as phantom selections like in that plugin and jump would just select next selection.

---

<div class="post-metadata">

**Author:** ![TeddyDD](https://discuss.kakoune.com/user_avatar/discuss.kakoune.com/teddydd/32/21_2.png) [@TeddyDD](https://discuss.kakoune.com/u/TeddyDD)\
**Post date:** [December 18, 2018, 10:54pm UTC](https://discuss.kakoune.com/t/need-snippets-we-got-snippets/42/15 "2018-12-18T22:54:36Z")

</div>

It seems that @occivink has created yet another snippet plugin. It looks promising, especially in conjuction with [phantom-selection](https://github.com/occivink/kakoune-phantom-selection) plugin!

> **[GitHub - occivink/kakoune-snippets: Snippet support for kakoune](https://github.com/occivink/kakoune-snippets)**
>
> Snippet support for kakoune. Contribute to occivink/kakoune-snippets development by creating an account on GitHub.

---

<div class="post-metadata">

**Author:** ![andreyorst](https://discuss.kakoune.com/user_avatar/discuss.kakoune.com/andreyorst/32/29_2.png) [@andreyorst](https://discuss.kakoune.com/u/andreyorst)\
**Post date:** [December 25, 2018, 11:37am UTC](https://discuss.kakoune.com/t/need-snippets-we-got-snippets/42/16 "2018-12-25T11:37:59Z")

</div>

Guys, @occivink is my hero now!

---

<div class="post-metadata">

**Author:** ![TeddyDD](https://discuss.kakoune.com/user_avatar/discuss.kakoune.com/teddydd/32/21_2.png) [@TeddyDD](https://discuss.kakoune.com/u/TeddyDD)\
**Post date:** [December 25, 2018, 1:32pm UTC](https://discuss.kakoune.com/t/need-snippets-we-got-snippets/42/17 "2018-12-25T13:32:28Z")

</div>

```auto
$ grep "occivink" kakrc wto, 25 gru 2018, 14:28:54
plug "https://github.com/occivink/kakoune-find"
plug "https://github.com/occivink/kakoune-expand"
plug "https://github.com/occivink/kakoune-phantom-selection" %{
plug "https://github.com/occivink/kakoune-sudo-write"
plug "https://github.com/occivink/kakoune-vertical-selection"
plug "https://github.com/occivink/kakoune-snippets" %{

```

yup, I agree

---

<div class="post-metadata">

**Author:** ![occivink](https://discuss.kakoune.com/user_avatar/discuss.kakoune.com/occivink/32/27_2.png) [@occivink](https://discuss.kakoune.com/u/occivink)\
**Post date:** [December 26, 2018, 1:41pm UTC](https://discuss.kakoune.com/t/need-snippets-we-got-snippets/42/18 "2018-12-26T13:41:26Z")

</div>

Thanks 🙂
