summaryrefslogtreecommitdiff
path: root/lua/config/luasnip.lua
diff options
context:
space:
mode:
authorbh <qn+git@excalibur.computer>2025-11-19 14:50:22 +0800
committerbh <qn+git@excalibur.computer>2025-11-19 14:50:22 +0800
commit5e80cc2081ec616c828a0abe82d246c4dc0a4334 (patch)
tree3805b57cdf59e0fa4dafb4c998f82644da19fb38 /lua/config/luasnip.lua
parentf3d3e0d5dc32bb5c00a6106aee9027decd345e63 (diff)
Fixed snippets and also a little refactoring on the theme
Diffstat (limited to 'lua/config/luasnip.lua')
-rw-r--r--lua/config/luasnip.lua67
1 files changed, 28 insertions, 39 deletions
diff --git a/lua/config/luasnip.lua b/lua/config/luasnip.lua
index 54ba5de..4524322 100644
--- a/lua/config/luasnip.lua
+++ b/lua/config/luasnip.lua
@@ -1,47 +1,36 @@
+-- Return a function so we can call it from Lazy.nvim
return function()
- local ls = require("luasnip")
- local s = ls.snippet
- local t = ls.text_node
- local i = ls.insert_node
+ local ls = require("luasnip")
- -- 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"})
- }),
- },
- }
+ -- Load snippets from friendly-snippets
+ require("luasnip.loaders.from_vscode").lazy_load()
- local opts = { silent = true, noremap = true }
+ -- Example Lua snippets
+ ls.add_snippets("lua", {
+ ls.parser.parse_snippet("hi", "print('Hello, world!')"),
+ ls.parser.parse_snippet("fn", "function ${1:name}(${2:args})\n\t$0\nend"),
+ })
- -- 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)
+ local opts = { silent = true, noremap = true }
- -- Jump backward
- vim.keymap.set({ "i", "s" }, "<C-h>", function()
- if ls.jumpable(-1) then
- ls.jump(-1)
- end
- end, opts)
+ -- Expand snippet or jump forward
+ vim.keymap.set({ "i", "s" }, "<C-k>", function()
+ if ls.expand_or_jumpable() then
+ ls.expand_or_jump()
+ 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)
+ -- Jump backward
+ vim.keymap.set({ "i", "s" }, "<C-j>", function()
+ if ls.jumpable(-1) then
+ ls.jump(-1)
+ end
+ end, opts)
- -- Load snippets
- require("luasnip.loaders.from_vscode").lazy_load()
+ -- Change choice in choice node
+ vim.keymap.set({ "i", "s" }, "<C-l>", function()
+ if ls.choice_active() then
+ ls.change_choice(1)
+ end
+ end, opts)
end
-