summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lua/config/luasnip.lua55
-rw-r--r--lua/config/snippets.lua19
-rw-r--r--lua/plugins/init.lua1
3 files changed, 61 insertions, 14 deletions
diff --git a/lua/config/luasnip.lua b/lua/config/luasnip.lua
index f3b39b4..54ba5de 100644
--- a/lua/config/luasnip.lua
+++ b/lua/config/luasnip.lua
@@ -1,20 +1,47 @@
return function()
- local ls = require("luasnip")
+ local ls = require("luasnip")
+ local s = ls.snippet
+ local t = ls.text_node
+ local i = ls.insert_node
- -- Expand snippet
- vim.keymap.set("i", "<C-K>", function() ls.expand() end, { silent = true })
+ -- 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"})
+ }),
+ },
+ }
- -- Jump forward/backward
- vim.keymap.set({ "i", "s" }, "<C-L>", function() ls.jump(1) end, { silent = true })
- vim.keymap.set({ "i", "s" }, "<C-J>", function() ls.jump(-1) end, { silent = true })
+ local opts = { silent = true, noremap = true }
- -- Change choice in choice node
- vim.keymap.set({ "i", "s" }, "<C-E>", function()
- if ls.choice_active() then
- ls.change_choice(1)
- end
- end, { silent = 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)
- -- Optionally, load snippets here if you have them
- -- require("luasnip.loaders.from_vscode").lazy_load()
+ -- 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
+
diff --git a/lua/config/snippets.lua b/lua/config/snippets.lua
new file mode 100644
index 0000000..8b0d30b
--- /dev/null
+++ b/lua/config/snippets.lua
@@ -0,0 +1,19 @@
+-- ~/.config/nvim/lua/snippets.lua
+local ls = require("luasnip")
+local s = ls.snippet
+local t = ls.text_node
+local i = ls.insert_node
+
+ls.snippets = {
+ all = {
+ s("hi", t("Hello, world!")), -- Type "hi" -> expand to Hello, world!
+ },
+ lua = {
+ s("fn", { -- Type "fn" -> expand to a function template
+ t("function "), i(1, "name"), t("("), i(2), t({")", "\t"}),
+ i(0),
+ t({"", "end"})
+ }),
+ },
+}
+
diff --git a/lua/plugins/init.lua b/lua/plugins/init.lua
index f66d9c6..760660f 100644
--- a/lua/plugins/init.lua
+++ b/lua/plugins/init.lua
@@ -46,6 +46,7 @@ return {
-- follow latest release.
version = "v2.*", -- Replace <CurrentMajor> by the latest released major (first number of latest release)
-- install jsregexp (optional!).
+ dependencies = { "rafamadriz/friendly-snippets" },
build = "make install_jsregexp",
config = function()
require("config.luasnip")()