Hello,
I would like to try the snippets here: https://github.com/occivink/kakoune-snippets
but I don’t quite know how.
In what file should the snippets go? Where should that file go? I think I am missing a few steps.
I’ve watched the asciinema demo but it does not show the keystrokes.
I ran the test mentioned in the readme, (kak -n -e ‘source test.kak_ ; quit’) and kakoune did not stay open so it seems to be installed correctly.
Thank you for any hints! (or other snippet suggestions for basic-level user).
Snippets with this plugin differs from those commonly implemented with vim type editors whose expansion mechanism fetches a template from a directory/file (often with one file per snippet definition).
Here, snippets are defined with set-option statements – you can for organization, place any or all of these directives in a separate .kak file and source them.
Hooks are the easiest way to associate a group of snippets with a particular filetype, e.g.
where,
<name> is the snippet name to display when you enter the command ":snippets "
<abbrev> is the trigger string to cause snippet expansion in insert mode
<snippet content> is the snippet string. This can be a simple string within %{ … } or a generated string e.g. %sh{ … }
Positional parameters are defined within the snippet content with ${label1}, ${label2}, etc.
In command mode, typing ":snippets " will bring up the snippet list “date img” (for markdown files) for selection and insert OR in insert mode, typing “@im” will immediately expand to its snippet content.
With your hint, I was able to add some snippets. Thank you. Namely, I put the following line in my kakrc file:
set-option -add global snippets ‘MYSNIPPET’ ‘SN1’ %{ snippets-insert %{THIS IS MY SNIPPET TEXT} }
When I type ":snippets " at the command prompt, I get this snippet. But I’m not able to get your hook part to work. The snippet is just not listed. I tried using extension .md for markdown, and I tried other filetypes. Do you manually source your snippet file, or is that done from within the kakrc file? Thank you so much.
Note “-add buffer”, NOT “-add global”. The snippet is defined within the hook block.
Two: Not sure if it is just the formatting on this web page, but the quotes should be the standard ascii quotes (not the curly utf-8 punctuation glyphs) surrounding the snippet name and trigger.
If you want your snippet to be global for any buffers (no hooks required)…
set-option global snippets '<name>' '<trigger>' %{ snippets-insert %{ <string> }}
The %{ string } can easily be %sh{ shell output command }
I wonder if there is something wrong with my set up. When I put the following lines in a file (mysnippets.kak), source it, and then invoke :snippets-info, I get only one the snippet ‘CALL’, as shown in the screenshot.
should be “set-option global …” (remove “-add”, and outside of any “hook global BufSetOption …” block.
The hook blocks look syntactically correct. Check the *debug* buffer… possibly an error affected the hook block. Again, if you are cutting and pasting from this web page, make sure the single/double quotes are the ascii quotes and not the curly utf-8 glyphs.
EDIT the above to remove the ‘-add’ is incorrect. If removed it will override any global snippets previously defined i.e. only one global snippet will be defined.
Hello, I’m still not able to get the hook part to work. I tried sourcing file with only your example snippets. I see that what I pasted into the post had curly quote marks but those are not in my actual file. I try here to post it:
I don’t get any error messages and the debug buffer is empty.
Is there a way to query in kakoune what filetype one has loaded?
I wonder if the filetype is not being detected properly.
Could it be because I didn’t install things correctly?
I didn’t use any plug-in manager. I just put the snippets.kak file
from Occivink in my autoload folder.
The snippets work if they are not in a hook command.
Thank you.
Ah, thank you. I installed Kakoune using homebrew on the mac. Is it expected that ‘menu’ be part of that installation or do we install it separately ourselves?
I haven’t tried the option of compling Kakoune from the source so far.
The directory you mention [ ~/.config/kak/autoload/rc ] is in our home directory, is that right? That directory is empty except what I put in it (the snippets.kak file from Occivink).
thank you…
(happy TGD)…
Yes, the menu module is part of the Kakoune package.
If you check the git repo you will see that you are missing all the rc directory modules… including the file detection modules (hence, your markdown filetype issues).
A complete kakoune install will probably solve your problems i’m not on the mac… but you may need to do a manual install from the git repo if homebrew doesn’t have the missing modules available separately. NOTE the MacPorts install instructions on the git page.
Good luck.
(and, yes, ~/.config/kak is in your home directory).
If you have created ~/.config/kak/autoload/ and it contains only rc/snippets.kak, then that’s the only file that will be loaded. Kakoune’s “standard library” should be installed in a system-wide location (you can check it with :info %val{runtime} inside Kakoune) but Kakoune will only read it if the per-user autoload directory doesn’t exist, or if there’s a symlink in the per-user autoload directory pointing at the standard library.
Hello. Thanks for this advice. I deleted my autoload folder and put the snippets file in the same folder as the file I am editing, for now, to test. Now the menu command works. But the hook command is working oddly. After sourcing the following snippet file, all 3 snippets are listed and available.
If i understand you correctly, you now have no autoload directory.
Without autoloading the Kakoune modules for filetypes, etc. your config is missing (i am assuming) the file detection required for markdown (and other filetypes).
Is there a kak “rc” directory elsewhere on your system? e.g.
find /usr -type d -name kak
or perhaps from a “homebrew” root. Assuming you have a “kak/…/rc” directory (a directory containing /detection, /filetype, /tools, and /windowing module subdirectories), then
(The filetype/markdown.kak module sets the markdown filetype for “markdown, md and mkd” files, as well as, highlighting, etc.)
I’m not familiar with the homebrew install so don’t know where it places Kakoune’s modules and whether any modules are autoloaded. snippets.kak is obviously able to “require” the menu module (which suggests it is located off the /usr directory).
See if fixing the autoload of the standard Kakoune modules clears up the irregular snippet behaviour you’ve been experiencing.
In the first two examples, the markdown snippets don’t show up.
In the second two examples, the availability of the .* snippets in the hook command are not available unless another snippet is defined after the hook command. Is there another syntax for the hook command to try?
Thank you.