{"id":13895378,"url":"https://github.com/occivink/kakoune-snippets","last_synced_at":"2025-07-17T11:30:36.504Z","repository":{"id":63142375,"uuid":"162345768","full_name":"occivink/kakoune-snippets","owner":"occivink","description":"Snippet support for kakoune","archived":false,"fork":false,"pushed_at":"2024-11-29T11:05:22.000Z","size":80,"stargazers_count":50,"open_issues_count":5,"forks_count":6,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-07-03T13:05:05.759Z","etag":null,"topics":["kakoune","plugin","snippets"],"latest_commit_sha":null,"homepage":"","language":"KakouneScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"unlicense","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/occivink.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-12-18T21:12:01.000Z","updated_at":"2025-04-26T11:29:59.000Z","dependencies_parsed_at":"2024-11-26T08:45:25.149Z","dependency_job_id":null,"html_url":"https://github.com/occivink/kakoune-snippets","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/occivink/kakoune-snippets","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/occivink%2Fkakoune-snippets","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/occivink%2Fkakoune-snippets/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/occivink%2Fkakoune-snippets/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/occivink%2Fkakoune-snippets/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/occivink","download_url":"https://codeload.github.com/occivink/kakoune-snippets/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/occivink%2Fkakoune-snippets/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265600484,"owners_count":23795704,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["kakoune","plugin","snippets"],"created_at":"2024-08-06T18:02:10.523Z","updated_at":"2025-07-17T11:30:36.499Z","avatar_url":"https://github.com/occivink.png","language":"KakouneScript","funding_links":[],"categories":["KakouneScript"],"sub_categories":[],"readme":"# kakoune-snippets\n\n**Disclaimer**: I've recently downsized the plugin and removed functionality. This is both for making the plugin more manageable, and so that I actually want to use and work on it. If you are interested in using (or forking) this previous state, you have my blessing (not that you need it). The latest commit of this state is 9c96e64a567ae5cb16d47cf9d3a56189f77c430c.\n\n(Yet another) [kakoune](http://kakoune.org) plugin for handling snippets.\n\n[![demo](https://asciinema.org/a/217470.png)](https://asciinema.org/a/217470)\n\n## Setup\n\nAdd `snippets.kak` to your autoload dir: `~/.config/kak/autoload/`, or source it manually.\n\nThis plugin requires the kakoune version `2022.10.31`.\n\n## Usage\n\nThe extension is configured via two options:\n* `snippets` `[str-list]` is a list of {name, trigger, command} tuples. The name is the identifier of the snippet, the trigger is a short string that identifies the snippet, and the command is what gets `eval`'d when the snippet is activated. In practice it's just a flat list that looks like `snip1-name` `snip1-trigger` `snip1-command` `snip2-name` `snip2-trigger` `snip2-command`...  \n* `snippets_auto_expand` `[bool]` controls whether triggers are automatically expanded when they are typed in insert mode. `true` by default.  \n\nSnippets can be selected manually with the commands `snippets` and `snippets-menu`.\n\nAt any moment, the `snippets-info` command can be used to show the available snippets and their respective triggers.\n\n### Triggers\n\nSnippets can be executed when a certain string is written directly in the buffer with the help of triggers. To each snippet is associated a regex which we call a trigger.\n\nTriggers can be automatically expanded by setting `snippets_auto_expand` to true, or they can be expanded manually by using the `snippets-expand-trigger` command. By default, this command tries to expand the current selection if it is a trigger, but you can also pass it an argument to select a different part of the buffer.\n\nThe option `snippets_triggers_regex` can be used to help select triggers. It's a simple alternation of all triggers as a single regex.\n\nFor example, this call will try to select a trigger on the current line and expand it. If it fails, the selection stays unmodified.\n```\nsnippets-expand-trigger %{\n    reg / \"%opt{snippets_triggers_regex}\"\n    # select to the beginning of the line, and then subselect for one of the triggers\n    exec 'hGhs\u003cret\u003e'\n}\n```\n\nIf a snippet does not have a trigger (i.e. it's empty), you won't be able to use it via expansion, but the basic commands `snippets` and `snippets-menu` can still be used.\n\n### Defining your own snippets\n\nSnippet commands are just regular kakoune command, so you can do just about anything in them.\n\nIdeally, your snippet command should work in both Insert and Normal mode, so that it can be used via auto-expansion and manual snippet call (be careful about this [kakoune issue](https://github.com/mawww/kakoune/issues/1916)).\n\n### `snippets-insert`\n\n`snippets-insert` is a builtin command of the script that can be used to insert text with proper indentation and optionally move/create cursors. It accepts one argument which is the snippet to be inserted at the cursor(s).\n\nTabs should be used for indentation when defining snippets, they will be automatically converted to the appropriate indentation level (depending on `indentwidth`)\n\nThe snippet supports custom syntax to define cursor placeholders, which define the resulting selections after expansion. A cursor placeholder is defined with `${}` (empty selection) or `${text}` (default selection text). `$n` will be transformed into newlines. To use a literal `$` inside a snippet or a literal `}` inside a placeholder, double it up (`$$` and `}}`).\n\nWhen a snippet is inserted with `snippets-insert`, all placeholders are selected. If there are none, the entire snippet is selected.\n\n## Changelog\n\n* Removed `snippets-directory.kak` and numbered placeholder support from `snippets-insert` (see disclaimer at the top)  \n* `${indent}` has been removed in favor of changing leading tabs to the preferred indentation  \n* any value can now be used as a trigger. They're regexes, so escape them accordingly  \n* implicit `\\b` are not inserted anymore before and after triggers. The internal option `%opt{snippets_expand_triggers}` has been renamed to `%opt{snippets_triggers_regex}`  \n* `snippets_triggers` and `snippets` have been merged into a single option  \n* triggers can now be manually expanded by calling the `snippets-expand-trigger` command on a valid trigger  \n* `snippets_auto_expand` is now a boolean that controls whether auto-expansion of triggers is enabled  \n* `snippets_auto_expand` was renamed to `snippets_triggers`  \n\n## FAQ\n\n### What's the performance impact of the extension?\n\nIf you use the auto-expansion feature, a runtime hook is run on each Insert mode key press. It only uses a shell scope in case of a match, and stops early otherwise.  \nIf you don't use it, there is no runtime cost (except when executing a snippet of course).\n\n### What's with escaping, what kind of characters can I use and not use?\n\nYou should be able to use anything. Triggers are currently restricted to at most 10 characters (at least for auto-expansion), but the number is arbitrary and we could raise it.\n\n### My snippets are expanding too greedily. If I type 'before', I don't want my 'for' snippet to be expanded.\n\nYou should use a stricter trigger for the snippet. For example, `\\bfor` will only expand if `for` starts at a word boundary. Similarly, you can use `^` to match the start of a line.\n\n### How did you do the demo?\n\nIt's done using kitty's remote control features, a 'manuscript' and a script to bridge the two. I'll upload them at some point.\n\n## Tests\n\nThe `test.kak_` file contains tests for the plugin. To execute these tests, simply run `kak -n -e 'source test.kak_ ; quit'`: if the kakoune instance stays open, the tests have somehow failed and the current state can be inspected.\n\n## Similar extensions\n\nhttps://github.com/alexherbo2/snippets.kak  \nhttps://github.com/shachaf/kak/blob/master/scripts/snippet.kak  \n\n## License\n\nUnlicense\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foccivink%2Fkakoune-snippets","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Foccivink%2Fkakoune-snippets","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foccivink%2Fkakoune-snippets/lists"}