summaryrefslogtreecommitdiff
path: root/lua/config/luasnip.lua
blob: 54ba5de7b785d8f7322d9196ac6ea226e2e0ba1d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
return function()
    local ls = require("luasnip")
    local s = ls.snippet
    local t = ls.text_node
    local i = ls.insert_node

    -- Minimal test snippet
    ls.snippets = {
        all = {
            s("hi", t("Hello, world!")),
        },
        lua = {
            s("fn", {
                t("function "), i(1, "name"), t("("), i(2), t({")", "\t"}),
                i(0),
                t({"", "end"})
            }),
        },
    }

    local opts = { silent = true, noremap = true }

    -- Expand or jump forward
    vim.keymap.set({ "i", "s" }, "<C-l>", function()
        if ls.expand_or_jumpable() then
            ls.expand_or_jump()
        end
    end, opts)

    -- Jump backward
    vim.keymap.set({ "i", "s" }, "<C-h>", function()
        if ls.jumpable(-1) then
            ls.jump(-1)
        end
    end, opts)

    -- Cycle choice nodes
    vim.keymap.set({ "i", "s" }, "<C-k>", function()
        if ls.choice_active() then
            ls.change_choice(1)
        end
    end, opts)

    -- Load snippets
    require("luasnip.loaders.from_vscode").lazy_load()
end