From 27a7c25f0727b373b5d0e4693d5bb2cb4c9c3a88 Mon Sep 17 00:00:00 2001 From: srdusr Date: Wed, 19 Oct 2022 23:55:51 +0200 Subject: Made Sourcing lua config easier --- lua/user/luasnip.lua | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 lua/user/luasnip.lua (limited to 'lua/user/luasnip.lua') 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" } }, -- + }, -- + }, -- + }, -- +} +-- is my expansion key +-- this will expand the current item or jump to the next item within the snippet. +vim.keymap.set({ "i", "s" }, "", function() + if ls.expand_or_jumpable() then + ls.expand_or_jump() + end +end, { silent = true }) + +-- is my jump backwards key. +-- this always moves to the previous item within the snippet +vim.keymap.set({ "i", "s" }, "", function() + if ls.jumpable(-1) then + ls.jump(-1) + end +end, { silent = true }) + +-- is selecting within a list of options. +-- This is useful for choice nodes (introduced in the forthcoming episode 2) +vim.keymap.set("i", "", function() + if ls.choice_active() then + ls.change_choice(1) + end +end) + +vim.keymap.set("i", "", require "luasnip.extras.select_choice") + +-- shorcut to source my luasnips file again, which will reload my snippets +vim.keymap.set("n", "s", "source ~/.config/nvim/lua/plugins/luasnip.lua") + +-- ls.parser.parse_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, +--}) + + + + -- cgit v1.2.3