From e327fb4f3ef1b6249ec724464ae6a5c34faa96e0 Mon Sep 17 00:00:00 2001 From: dogeystamp Date: Tue, 2 Apr 2024 22:37:58 -0400 Subject: [PATCH] [wip] nvim: begin migrating to luasnip --- .gitmodules | 16 +++++++---- src/.config/nvim/init.vim | 2 -- src/.config/nvim/lua/coding.lua | 9 ++++-- src/.config/nvim/lua/confutil.lua | 2 +- src/.config/nvim/lua/init.lua | 1 + src/.config/nvim/lua/snippets.lua | 28 +++++++++++++++++++ src/.config/nvim/snippets/all.lua | 5 ++++ src/.config/nvim/ultisnips.vim | 9 ------ .../share/nvim/site/pack/3pp/opt/ultisnips | 1 - .../share/nvim/site/pack/3pp/start/LuaSnip | 1 + .../nvim/site/pack/3pp/start/cmp_luasnip | 1 + 11 files changed, 54 insertions(+), 21 deletions(-) create mode 100644 src/.config/nvim/lua/snippets.lua create mode 100644 src/.config/nvim/snippets/all.lua delete mode 100644 src/.config/nvim/ultisnips.vim delete mode 160000 src/.local/share/nvim/site/pack/3pp/opt/ultisnips create mode 160000 src/.local/share/nvim/site/pack/3pp/start/LuaSnip create mode 160000 src/.local/share/nvim/site/pack/3pp/start/cmp_luasnip diff --git a/.gitmodules b/.gitmodules index 5acdb4e..249adfc 100644 --- a/.gitmodules +++ b/.gitmodules @@ -73,12 +73,6 @@ path = src/.local/share/nvim/site/pack/3pp/start/typst.vim url = https://github.com/kaarmu/typst.vim.git -# snippet engine -# ultisnips.vim -[submodule "src/.local/share/nvim/site/pack/3pp/opt/ultisnips"] - path = src/.local/share/nvim/site/pack/3pp/opt/ultisnips - url = https://github.com/SirVer/ultisnips.git - # color theme # init.lua [submodule "src/.local/share/nvim/site/pack/3pp/start/nvim-noirbuddy"] @@ -99,3 +93,13 @@ [submodule "src/.local/share/nvim/site/pack/3pp/start/nvim-nio"] path = src/.local/share/nvim/site/pack/3pp/start/nvim-nio url = https://github.com/nvim-neotest/nvim-nio + +# snippet support +# snippets.lua +# (also coding.lua becuase nvim-cmp uses this too) +[submodule "src/.local/share/nvim/site/pack/3pp/start/LuaSnip"] + path = src/.local/share/nvim/site/pack/3pp/start/LuaSnip + url = https://github.com/L3MON4D3/LuaSnip +[submodule "src/.local/share/nvim/site/pack/3pp/start/cmp_luasnip"] + path = src/.local/share/nvim/site/pack/3pp/start/cmp_luasnip + url = https://github.com/saadparwaiz1/cmp_luasnip diff --git a/src/.config/nvim/init.vim b/src/.config/nvim/init.vim index ba6cc08..17eb968 100755 --- a/src/.config/nvim/init.vim +++ b/src/.config/nvim/init.vim @@ -77,8 +77,6 @@ endif filetype plugin indent on -source $XDG_CONFIG_HOME/nvim/ultisnips.vim - if $SYSTEM_PROFILE == "DEFAULT" " plugins for IDE-like nvim source $XDG_CONFIG_HOME/nvim/coding.vim diff --git a/src/.config/nvim/lua/coding.lua b/src/.config/nvim/lua/coding.lua index 2a18331..bae3221 100644 --- a/src/.config/nvim/lua/coding.lua +++ b/src/.config/nvim/lua/coding.lua @@ -176,11 +176,16 @@ cmp.setup({ documentation = cmp.config.window.bordered(), }, mapping = cmp.mapping.preset.insert({ - [''] = cmp.mapping.abort(), [''] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items. }), + snippet = { + expand = function(args) + require("luasnip").lsp_expand(args.body) + end + }, sources = cmp.config.sources({ { name = 'nvim_lsp' }, + { name = 'luasnip' }, { name = 'buffer' }, - }) + }), }) diff --git a/src/.config/nvim/lua/confutil.lua b/src/.config/nvim/lua/confutil.lua index c68902e..6cc9131 100644 --- a/src/.config/nvim/lua/confutil.lua +++ b/src/.config/nvim/lua/confutil.lua @@ -24,7 +24,7 @@ function M.keymap(key, cmd, params) end }) - vim.keymap.set(params.mode, key, cmd, { silent = params.silent, noremap = params.noremap }) + vim.keymap.set(params.mode, key, cmd, { silent = params.silent, noremap = params.noremap, expr = params.expr }) end -- see ~/.config/dot_profile.example for info diff --git a/src/.config/nvim/lua/init.lua b/src/.config/nvim/lua/init.lua index fe4ad31..39377d5 100644 --- a/src/.config/nvim/lua/init.lua +++ b/src/.config/nvim/lua/init.lua @@ -37,6 +37,7 @@ keymap("eb", "Telescope keymaps") -------------------------------- require("theme") +require("snippets") if dotprofile >= profile_table.DEFAULT then require("coding") diff --git a/src/.config/nvim/lua/snippets.lua b/src/.config/nvim/lua/snippets.lua new file mode 100644 index 0000000..1e78d8e --- /dev/null +++ b/src/.config/nvim/lua/snippets.lua @@ -0,0 +1,28 @@ +-- Snippet engine + +-- see coding.lua because it also uses luasnip +-- snippets live in .config/nvim/snippets/ + +local confutil = require("confutil") +local keymap = confutil.keymap + +-------------------------------- +-- key bindings +-------------------------------- + +-- could not manage to replicate this behaviour in lua +-- if you nvim_feedkeys to pass through the it infinite-loops +-- and also expr seems broken on my keymap() func +vim.cmd([[ +imap luasnip#expand_or_jumpable() ? 'luasnip-expand-or-jump' : '' +]]) + +keymap("", "luasnip-jump-next", { mode = { "s" } }) +keymap("", "luasnip-jump-prev", { mode = { "s", "i" } }) +keymap("", "luasnip-next-choice", { mode = { "s", "i" } }) + +-------------------------------- +-- snippets +-------------------------------- + +require("luasnip.loaders.from_lua").load({paths = vim.env.XDG_CONFIG_HOME .. "/nvim/snippets"}) diff --git a/src/.config/nvim/snippets/all.lua b/src/.config/nvim/snippets/all.lua new file mode 100644 index 0000000..4e42157 --- /dev/null +++ b/src/.config/nvim/snippets/all.lua @@ -0,0 +1,5 @@ +return { + s({ trig = "today", desc = "YYYY-MM-DD date of today" }, f(function () + return os.date("%Y-%m-%d") + end)) +} diff --git a/src/.config/nvim/ultisnips.vim b/src/.config/nvim/ultisnips.vim deleted file mode 100644 index 7e72991..0000000 --- a/src/.config/nvim/ultisnips.vim +++ /dev/null @@ -1,9 +0,0 @@ -" snippet engine (see .config/nvim/ultisnips/) - -if has('python3') && ($SYSTEM_PROFILE == "DEFAULT" || $SYSTEM_PROFILE == "SLIM") - packadd ultisnips - let g:UltiSnipsExpandTrigger="" - let g:UltiSnipsJumpForwardTrigger="" - let g:UltiSnipsJumpBackwardTrigger="" - let g:UltiSnipsSnippetDirectories=[$HOME.'/.config/nvim/ultisnips/'] -endif diff --git a/src/.local/share/nvim/site/pack/3pp/opt/ultisnips b/src/.local/share/nvim/site/pack/3pp/opt/ultisnips deleted file mode 160000 index b393ba6..0000000 --- a/src/.local/share/nvim/site/pack/3pp/opt/ultisnips +++ /dev/null @@ -1 +0,0 @@ -Subproject commit b393ba65386d47664421e1f8b246a87a6e8b218c diff --git a/src/.local/share/nvim/site/pack/3pp/start/LuaSnip b/src/.local/share/nvim/site/pack/3pp/start/LuaSnip new file mode 160000 index 0000000..825a61b --- /dev/null +++ b/src/.local/share/nvim/site/pack/3pp/start/LuaSnip @@ -0,0 +1 @@ +Subproject commit 825a61bad1d60d917a7962d73cf3c683f4e0407e diff --git a/src/.local/share/nvim/site/pack/3pp/start/cmp_luasnip b/src/.local/share/nvim/site/pack/3pp/start/cmp_luasnip new file mode 160000 index 0000000..05a9ab2 --- /dev/null +++ b/src/.local/share/nvim/site/pack/3pp/start/cmp_luasnip @@ -0,0 +1 @@ +Subproject commit 05a9ab28b53f71d1aece421ef32fee2cb857a843