Micron Document
neovim snippets

I was getting really frustrated trying to figure out how to use snippets. I just couldn't make sense of the T383838:help vim.snippets stuff. Mostly I actually kind of get how they should work with regard to jumping and replacing tokens, but I coulddn't figure out how to make snippets.

I'm still using folke's Lazy plugin manager, and so I dug into T383838LuaSnips -- specifically L3MON4D3/LuaSnip. Since I'm using some stuff from kickstart-nvim I get some completion stuf for free. So I just needed to figure out the syntax for how to make snippets.

I found a nice article on it and spent some time working through examples.

After some trial and error, I now have this for reference links and reference links with a caption:

Here's the reference link with no title, complete with document hover:

T282828
Td2a8ffsnipTb4b4b4({
Te6edf3trig Tff7b72= Ta5d6ff"Ta5d6ffrlTa5d6ff"Tb4b4b4,
Te6edf3desc Tff7b72= Tb4b4b4{
Ta5d6ff"Ta5d6ffreference link without title/captionTa5d6ff"Tb4b4b4,
Ta5d6ff"Ta5d6ff [[foo]]: bar.muTa5d6ff"Tb4b4b4,
Tb4b4b4},
Tb4b4b4}, Td2a8fffmtTb4b4b4([[ Tb4b4b4[{}]: Tb4b4b4{} Tb4b4b4]], Tb4b4b4{ Td2a8ffiTb4b4b4(T79c0ff1Tb4b4b4, Ta5d6ff"Ta5d6ffreferenceTa5d6ff"Tb4b4b4), Td2a8ffiTb4b4b4(T79c0ff2Tb4b4b4, Ta5d6ff"Ta5d6fflinkTa5d6ff"Tb4b4b4) Tb4b4b4}))


And that's cool, but for some reason, the T383838fmt function didn't work for me and I had to go hunting for it and wire it up on my own and assign a local variable for it:

T282828
Tff7b72local Te6edf3fmt Tff7b72= Tffa657requireTb4b4b4(Ta5d6ff"Ta5d6ffluasnip.extras.fmtTa5d6ff"Tb4b4b4).Te6edf3fmt


Here's a more complete example of it in a function that can be called to add the snippet configuration:

T282828
Te6edf3config Tff7b72= Tff7b72functionTb4b4b4(Tb4b4b4)
Tff7b72local Te6edf3luasnip Tff7b72= Tffa657requireTb4b4b4(Ta5d6ff"Ta5d6ffluasnipTa5d6ff"Tb4b4b4)
Tff7b72local Te6edf3fmt Tff7b72= Tffa657requireTb4b4b4(Ta5d6ff"Ta5d6ffluasnip.extras.fmtTa5d6ff"Tb4b4b4).Te6edf3fmt
Tff7b72local Te6edf3snip Tff7b72= Te6edf3luasnipTb4b4b4.Te6edf3snippet
Tff7b72local Te6edf3t Tff7b72= Te6edf3luasnipTb4b4b4.Te6edf3text_node
Tff7b72local Te6edf3i Tff7b72= Te6edf3luasnipTb4b4b4.Te6edf3insert_node
Tff7b72local Te6edf3p Tff7b72= Tffa657requireTb4b4b4(Ta5d6ff"Ta5d6ffluasnip.extrasTa5d6ff"Tb4b4b4).Te6edf3partial

Te6edf3luasnipTb4b4b4.Td2a8ffadd_snippetsTb4b4b4(Ta5d6ff"Ta5d6ffmarkdownTa5d6ff"Tb4b4b4, Tb4b4b4{
Td2a8ffsnipTb4b4b4({
Te6edf3trig Tff7b72= Ta5d6ff"Ta5d6ffrlTa5d6ff"Tb4b4b4,
Te6edf3desc Tff7b72= Tb4b4b4{
Ta5d6ff"Ta5d6ffreference link without title/captionTa5d6ff"Tb4b4b4,
Ta5d6ff"Ta5d6ff [[foo]]: bar.muTa5d6ff"Tb4b4b4,
Tb4b4b4},
Tb4b4b4}, Td2a8fffmtTb4b4b4([[ Tb4b4b4[{}]: Tb4b4b4{} Tb4b4b4]], Tb4b4b4{ Td2a8ffiTb4b4b4(T79c0ff1Tb4b4b4, Ta5d6ff"Ta5d6ffreferenceTa5d6ff"Tb4b4b4), Td2a8ffiTb4b4b4(T79c0ff2Tb4b4b4, Ta5d6ff"Ta5d6fflinkTa5d6ff"Tb4b4b4) Tb4b4b4})),
Tb4b4b4})


And with that I can now use rl and that will expand to T383838[reference]: link which advances the cursor to T383838reference, waiting for me to type in the field and then move to the next to replace the T383838link with a real target. My thinking was that I could complete the T383838reference with something previously typed in T383838[brackets] and then launch Telescope to resolvethe T383838link. And it's not to bad.

Marksman can complete links, but it doesn't use reference format, or I haven't figured out how to get it to. But now I don't need to.

I also added a snippet for reference links with titles or captions:

T282828
Td2a8ffsnipTb4b4b4({
Te6edf3trig Tff7b72= Ta5d6ff"Ta5d6ffrltTa5d6ff"Tb4b4b4,
Te6edf3desc Tff7b72= Tb4b4b4{
Ta5d6ff"Ta5d6ffreference link withtitle/captionTa5d6ff"Tb4b4b4,
Ta5d6ff'Ta5d6ff [[foo]]: bar.mu "title/caption"Ta5d6ff'Tb4b4b4,
Tb4b4b4},
Tb4b4b4}, Td2a8fffmtTb4b4b4([[ Tb4b4b4[{}]: Tb4b4b4{} Ta5d6ff"Ta5d6ff{}Ta5d6ff" Tb4b4b4]], Tb4b4b4{ Td2a8ffiTb4b4b4(T79c0ff1Tb4b4b4, Ta5d6ff"Ta5d6ffreferenceTa5d6ff"Tb4b4b4), Td2a8ffiTb4b4b4(T79c0ff2Tb4b4b4, Ta5d6ff"Ta5d6fflinkTa5d6ff"Tb4b4b4), Td2a8ffiTb4b4b4(T79c0ff3Tb4b4b4, Ta5d6ff"Ta5d6fftitleTa5d6ff"Tb4b4b4) Tb4b4b4}))


And while I do have a T383838template.mu that I can insert, I wanted to see what my yaml header would look like as a snippet, so I made that, too:

T282828
Td2a8ffsnipTb4b4b4(
Tb4b4b4{
Te6edf3trig Tff7b72= Ta5d6ff"Ta5d6ffyhTa5d6ff"Tb4b4b4,
Te6edf3desc Tff7b72= Tb4b4b4{
Ta5d6ff"Ta5d6ffYAML Header for notes, with tags and title.Ta5d6ff"Tb4b4b4,
Ta5d6ff"Ta5d6ffThis is my usual template for plain or atomic notes.Ta5d6ff"Tb4b4b4,
Tb4b4b4},
Tb4b4b4},
Td2a8fffmtTb4b4b4(
Ta5d6ff[[
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
tags: [ {} ]
title: "{}"
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

{}
]]Tb4b4b4,
Tb4b4b4{ Td2a8ffiTb4b4b4(T79c0ff1Tb4b4b4, Ta5d6ff"Ta5d6fftagsTa5d6ff"Tb4b4b4), Td2a8ffiTb4b4b4(T79c0ff2Tb4b4b4, Ta5d6ff"Ta5d6fftitleTa5d6ff"Tb4b4b4), Td2a8ffiTb4b4b4(T79c0ff3Tb4b4b4, Ta5d6ff"Ta5d6ffbodyTa5d6ff"Tb4b4b4) Tb4b4b4}
Tb4b4b4)
Tb4b4b4),


This produces:

tags: [ tags ]
title: "title"

body

And the cursor moves to T383838tags, I generally forget I'm moving between jumps when I finish the title, but if I go back into insert mode I can then jump to the body as though I never made the mistake.

I suspect I can drop LuaSnip entirely if I could just figure out how to put snippets into vim.snippet! Time to look at the source, I guess.

Tags: nvim

Tags
Navigation
Backlinks


created: 2025-10-18

updated: 2025-10-19 09:59:30

(re)generated: 2026-07-17