aboutsummaryrefslogtreecommitdiff
path: root/lua/user/luasnip.lua
diff options
context:
space:
mode:
Diffstat (limited to 'lua/user/luasnip.lua')
-rw-r--r--lua/user/luasnip.lua80
1 files changed, 80 insertions, 0 deletions
diff --git a/lua/user/luasnip.lua b/lua/user/luasnip.lua
new file mode 100644
index 0000000..12352e8
--- /dev/null
+++ b/lua/user/luasnip.lua
@@ -0,0 +1,80 @@
+if vim.g.snippets ~= "luasnip" or not pcall(require, "luasnip") then
+ return
+end
+--local luasnip = require("luasnip")
+local ls = require "luasnip" --
+local types = require "luasnip.util.types" --
+local options = {
+ history = true,
+ updateevents = "TextChanged,TextChangedI",
+ -- Autosnippets:
+ enable_autosnippets = true, --
+ ext_opts = { --
+ [types.choiceNode] = { --
+ active = { --
+ virt_text = { { " « ", "NonTest" } }, --
+ }, --
+ }, --
+ }, --
+}
+-- <c-k> is my expansion key
+-- this will expand the current item or jump to the next item within the snippet.
+vim.keymap.set({ "i", "s" }, "<c-.>", function()
+ if ls.expand_or_jumpable() then
+ ls.expand_or_jump()
+ end
+end, { silent = true })
+
+-- <c-j> is my jump backwards key.
+-- this always moves to the previous item within the snippet
+vim.keymap.set({ "i", "s" }, "<c-,>", function()
+ if ls.jumpable(-1) then
+ ls.jump(-1)
+ end
+end, { silent = true })
+
+-- <c-l> is selecting within a list of options.
+-- This is useful for choice nodes (introduced in the forthcoming episode 2)
+vim.keymap.set("i", "<c-l>", function()
+ if ls.choice_active() then
+ ls.change_choice(1)
+ end
+end)
+
+vim.keymap.set("i", "<c-c>", require "luasnip.extras.select_choice")
+
+-- shorcut to source my luasnips file again, which will reload my snippets
+vim.keymap.set("n", "<leader><leader>s", "<cmd>source ~/.config/nvim/lua/plugins/luasnip.lua<CR>")
+
+-- ls.parser.parse_snippet(<text>, <VS**** style snippet>)
+ls.snippets = {
+ all = {
+ -- Available in any filetype
+ ls.parser.parse_snippet("expand", "-- this is what was expanded!"),
+ },
+ lua = {
+ -- Lua specific snippets go here.
+ },
+}
+
+
+
+
+--luasnip.config.set_config(options)
+--require("luasnip.loaders.from_vscode").lazy_load()
+--require("luasnip.loaders.from_vscode").lazy_load { paths = vim.g.luasnippets_path or "" }
+--
+--vim.api.nvim_create_autocmd("InsertLeave", {
+-- callback = function()
+-- if
+-- require("luasnip").session.current_nodes[vim.api.nvim_get_current_buf()]
+-- and not require("luasnip").session.jump_active
+-- then
+-- require("luasnip").unlink_current()
+-- end
+-- end,
+--})
+
+
+
+