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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
return {
{
"L3MON4D3/LuaSnip",
version = "v2.*",
build = "make install_jsregexp",
dependencies = {
"rafamadriz/friendly-snippets",
config = function()
require("luasnip.loaders.from_vscode").lazy_load()
end,
},
config = function()
local ls = require("luasnip")
ls.setup({
link_children = true,
link_roots = false,
keep_roots = false,
update_events = { "TextChanged", "TextChangedI" },
})
local c = ls.choice_node
ls.choice_node = function(pos, choices, opts)
if opts then
opts.restore_cursor = true
else
opts = { restore_cursor = true }
end
return c(pos, choices, opts)
end
require("luasnip.loaders.from_vscode").lazy_load({
paths = { '"' .. vim.fn.stdpath("config") .. '/lua/thesiahxyz/snippets"' },
})
vim.cmd.runtime({ args = { "lua/thesiahxyz/snippets/*.lua" }, bang = true }) -- load custom snippets
vim.keymap.set({ "i", "x" }, "<A-L>", function()
if ls.expand_or_jumpable() then
ls.expand_or_jump()
end
end, { silent = true, desc = "Expand snippet or jump to the next snippet node" })
vim.keymap.set({ "i", "x" }, "<A-H>", function()
if ls.jumpable(-1) then
ls.jump(-1)
end
end, { silent = true, desc = "Previous spot in the snippet" })
vim.keymap.set({ "i", "x" }, "<A-l>", function()
if ls.choice_active() then
ls.change_choice(1)
end
end, { silent = true, desc = "Next snippet choice" })
vim.keymap.set({ "i", "x" }, "<A-h>", function()
if ls.choice_active() then
ls.change_choice(-1)
end
end, { silent = true, desc = "Previous snippet choice" })
end,
keys = {
vim.keymap.set("i", "<tab>", function()
return require("luasnip").jumpable(1) and "<Plug>luasnip-jump-next" or "<tab>"
end, { expr = true, silent = true, desc = "Jump to next snippet" }),
vim.keymap.set("s", "<tab>", function()
require("luasnip").jump(1)
end, { desc = "Jump to next snippet" }),
vim.keymap.set({ "i", "s" }, "<s-tab>", function()
require("luasnip").jump(-1)
end, { desc = "Jump to Previous Snippet" }),
},
},
}
|