From b7a7a40ff171aa2e6b7db87736f2c9f777aa464b Mon Sep 17 00:00:00 2001 From: Raymaekers Luca Date: Sat, 28 Sep 2024 01:17:06 +0200 Subject: added snippets and changed the keybinds Also removed luasnip source for completion --- after/plugin/luasnip.lua | 24 +++++++++++++++++------- lua/config/lsp.lua | 2 +- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/after/plugin/luasnip.lua b/after/plugin/luasnip.lua index e882168..9943ba3 100644 --- a/after/plugin/luasnip.lua +++ b/after/plugin/luasnip.lua @@ -5,15 +5,17 @@ local t = ls.text_node local map = vim.keymap.set -map("i", "", function() +map("i", "", function() if ls.expand_or_locally_jumpable() then ls.expand_or_jump() end end, { silent = true }) -map({ "i", "s" }, "", function() - ls.locally_jumpable(-1) -end, { silent = true }) map({ "i", "s" }, "", function() + if ls.locally_jumpable(-1) then + ls.jump(-1) + end +end, { silent = true }) +map({ "i", "s" }, "", function() if ls.choice_active() then ls.change_choice(1) end @@ -26,6 +28,14 @@ ls.config.set_config({ history = true, }) --- ls.add_snippets("all", { --- ls.parser.parse_snippet("expand", "-- this is $1 expanded $2 $3!"), --- }) +ls.add_snippets("all", { + ls.parser.parse_snippet("test", "$1->$2->$3->$0\n"), +}) +ls.add_snippets("go", { + ls.parser.parse_snippet("main", "package main\n\nfunc main() {\n\t$0\n}"), + ls.parser.parse_snippet("e", "if err != nil {\n\t$1\n}\n$0"), + ls.parser.parse_snippet("ep", "if err != nil {\n\tpanic(err)\n}\n$0"), + ls.parser.parse_snippet("eif", "if err := $1; err != nil {\n\tpanic(err)\n}\n$0"), + ls.parser.parse_snippet("pf", "fmt.Printf($0)"), + ls.parser.parse_snippet("pl", "fmt.Println($0)"), +}) diff --git a/lua/config/lsp.lua b/lua/config/lsp.lua index 346f791..d5645af 100644 --- a/lua/config/lsp.lua +++ b/lua/config/lsp.lua @@ -96,7 +96,7 @@ cmp.setup({ name = "nvim_lsp", keyword_length = 3, }, - { name = "luasnip" }, + -- { name = "luasnip" }, }, { -- { name = "buffer", max_item_count = 5 }, { name = "path", max_item_count = 5 }, -- cgit v1.2.3