From bd11cd4ed27f0fc504123628fa52c32cc8ead405 Mon Sep 17 00:00:00 2001 From: Dietrich Rink Date: Sat, 10 Jun 2023 15:18:53 +0200 Subject: [PATCH] replace luasnip with vsnip --- basic/Containerfile | 6 +++--- basic/nvim/init/00-basic.lua | 4 ++-- basic/nvim/luasnippets/all.lua | 25 ----------------------- basic/nvim/plugconf/LuaSnip.lua | 13 ------------ basic/nvim/plugconf/cmp.lua | 31 +++++++++++++++++++---------- basic/nvim/plugconf/vsnip.lua | 3 +++ basic/nvim/snippets/global.snippets | 4 ++++ go/nvim/luasnippets/go.lua | 10 ---------- go/nvim/snippets/go.snippets | 6 ++++++ 9 files changed, 38 insertions(+), 64 deletions(-) delete mode 100644 basic/nvim/luasnippets/all.lua delete mode 100644 basic/nvim/plugconf/LuaSnip.lua create mode 100644 basic/nvim/plugconf/vsnip.lua create mode 100644 basic/nvim/snippets/global.snippets delete mode 100644 go/nvim/luasnippets/go.lua create mode 100644 go/nvim/snippets/go.snippets diff --git a/basic/Containerfile b/basic/Containerfile index 8a2ea90..f04e9f8 100644 --- a/basic/Containerfile +++ b/basic/Containerfile @@ -11,9 +11,9 @@ RUN printf '%s\n' \ christoomey/vim-tmux-navigator benmills/vimux ap/vim-buftabline \ nvim-tree/nvim-tree.lua nvim-tree/nvim-web-devicons ctrlpvim/ctrlp.vim \ hrsh7th/nvim-cmp ray-x/lsp_signature.nvim hrsh7th/cmp-buffer \ - hrsh7th/cmp-nvim-lsp neovim/nvim-lspconfig saadparwaiz1/cmp_luasnip \ - L3MON4D3/LuaSnip jiangmiao/auto-pairs tpope/vim-surround tpope/vim-repeat \ - hrsh7th/cmp-path hrsh7th/cmp-nvim-lua \ + hrsh7th/cmp-path hrsh7th/cmp-nvim-lua hrsh7th/cmp-nvim-lsp \ + neovim/nvim-lspconfig hrsh7th/vim-vsnip hrsh7th/cmp-vsnip \ + jiangmiao/auto-pairs tpope/vim-surround tpope/vim-repeat \ rebelot/kanagawa.nvim \ | xargs -n1 -P0 -I'{}' git clone --depth 1 'https://github.com/{}' RUN printf 'helptags %s\n' */doc | nvim --noplugin -es diff --git a/basic/nvim/init/00-basic.lua b/basic/nvim/init/00-basic.lua index 64b43b9..111880f 100644 --- a/basic/nvim/init/00-basic.lua +++ b/basic/nvim/init/00-basic.lua @@ -11,15 +11,15 @@ pack 'ctrlp.vim' -- Language servers and snippets pack 'nvim-lspconfig' -pack 'LuaSnip' pack 'lsp_signature.nvim' +pack 'vim-vsnip' -- Completion pack 'cmp-buffer' pack 'cmp-path' pack 'cmp-nvim-lua' pack 'cmp-nvim-lsp' -pack 'cmp_luasnip' +pack 'cmp-vsnip' pack 'nvim-cmp' -- Editing diff --git a/basic/nvim/luasnippets/all.lua b/basic/nvim/luasnippets/all.lua deleted file mode 100644 index 48ad8e9..0000000 --- a/basic/nvim/luasnippets/all.lua +++ /dev/null @@ -1,25 +0,0 @@ -return { - parse( - { trig = 'lorem', name = 'Lorem ipsum sentence' }, - table.concat({ - 'Lorem ipsum dolor sit amet, qui minim labore adipisicing minim sint', - 'cillum sint consectetur cupidatat.', - }, " ") - ), - parse( - { trig = 'loremipsum', name = "Lorem ipsum paragraph" }, - table.concat({ - 'Lorem ipsum dolor sit amet, officia excepteur ex fugiat reprehenderit', - 'enim labore culpa sint ad nisi Lorem pariatur mollit ex esse', - 'exercitation amet. Nisi anim cupidatat excepteur officia.', - 'Reprehenderit nostrud nostrud ipsum Lorem est aliquip amet voluptate', - 'voluptate dolor minim nulla est proident. Nostrud officia pariatur ut', - 'officia. Sit irure elit esse ea nulla sunt ex occaecat reprehenderit', - 'commodo officia dolor Lorem duis laboris cupidatat officia voluptate.', - 'Culpa proident adipisicing id nulla nisi laboris ex in Lorem sunt duis', - 'officia eiusmod. Aliqua reprehenderit commodo ex non excepteur duis', - 'sunt velit enim. Voluptate laboris sint cupidatat ullamco ut ea', - 'consectetur et est culpa et culpa duis.', - }, ' ') - ), -} diff --git a/basic/nvim/plugconf/LuaSnip.lua b/basic/nvim/plugconf/LuaSnip.lua deleted file mode 100644 index 3116e6c..0000000 --- a/basic/nvim/plugconf/LuaSnip.lua +++ /dev/null @@ -1,13 +0,0 @@ -local luasnip = require 'luasnip' -local loader = require 'luasnip.loaders.from_lua' - -luasnip.setup { - -- Enable live updates - update_events = { 'TextChanged', 'TextChangedI' }, - - -- Stop jumping when deleted - delete_check_events = { 'TextChanged' }, -} - --- Automatically load lua snippets -loader.lazy_load() diff --git a/basic/nvim/plugconf/cmp.lua b/basic/nvim/plugconf/cmp.lua index e65deb4..e748be2 100644 --- a/basic/nvim/plugconf/cmp.lua +++ b/basic/nvim/plugconf/cmp.lua @@ -1,13 +1,18 @@ local cmp = require 'cmp' local context = require 'cmp.config.context' -local luasnip = require 'luasnip' vim.o.completeopt = nil +-- Plugin helper +local feedkey = function(key, mode) + key = vim.api.nvim_replace_termcodes(key, true, true, true) + vim.api.nvim_feedkeys(key, mode, true) +end + -- General setup cmp.setup { snippet = { - expand = function(args) luasnip.lsp_expand(args.body) end, + expand = function(args) vim.fn['vsnip#anonymous'](args.body) end, }, window = { documentation = { border = 'rounded' }, @@ -17,7 +22,7 @@ cmp.setup { format = function(entry, item) item.menu = ({ nvim_lsp = 'λ', - luasnip = '⋗', + vsnip = '⋗', buffer = 'Ω', path = '🖫', })[entry.source.name] @@ -30,10 +35,10 @@ cmp.setup { [''] = cmp.mapping(function(fallback) if cmp.get_selected_entry() then cmp.confirm() - elseif luasnip.jumpable(1) then - luasnip.jump(1) - elseif luasnip.expandable() then - luasnip.expand() + elseif vim.fn['vsnip#jumpable'](1) == 1 then + feedkey('(vsnip-jump-next)', '') + elseif vim.fn['vsnip#expandable']() == 1 then + feedkey('(vsnip-expand)', '') elseif cmp.visible() then cmp.select_next_item() else @@ -42,8 +47,8 @@ cmp.setup { end, { 'i', 's' }), -- Jump back with shift tab [''] = cmp.mapping(function(fallback) - if luasnip.jumpable(-1) then - luasnip.jump(-1) + if vim.fn['vsnip#jumpable'](-1) == 1 then + feedkey('(vsnip-jump-prev)', '') else fallback() end @@ -57,12 +62,16 @@ cmp.setup { end end), [''] = cmp.mapping(function(fallback) - if cmp.visible() then cmp.select_prev_item() else fallback() end + if cmp.visible() then + cmp.select_prev_item() + else + fallback() + end end), }, sources = cmp.config.sources({ { name = 'nvim_lsp' }, - { name = 'luasnip' }, + { name = 'vsnip' }, { name = 'nvim_lua' }, }, { { name = 'buffer', keyword_length = 5 }, diff --git a/basic/nvim/plugconf/vsnip.lua b/basic/nvim/plugconf/vsnip.lua new file mode 100644 index 0000000..40cf7ce --- /dev/null +++ b/basic/nvim/plugconf/vsnip.lua @@ -0,0 +1,3 @@ +vim.g.vsnip_snippet_dir = '/etc/xdg/nvim/snippets' +vim.g.vsnip_deactivate_on = 2 + diff --git a/basic/nvim/snippets/global.snippets b/basic/nvim/snippets/global.snippets new file mode 100644 index 0000000..8bbdf7e --- /dev/null +++ b/basic/nvim/snippets/global.snippets @@ -0,0 +1,4 @@ +snippet lorem + Lorem ipsum dolor sit amet, qui minim labore adipisicing minim sint cillum sint consectetur cupidatat. +snippet loremipsum + Lorem ipsum dolor sit amet, officia excepteur ex fugiat reprehenderit enim labore culpa sint ad nisi Lorem pariatur mollit ex esse exercitation amet. Nisi anim cupidatat excepteur officia. Reprehenderit nostrud nostrud ipsum Lorem est aliquip amet voluptate voluptate dolor minim nulla est proident. Nostrud officia pariatur ut officia. Sit irure elit esse ea nulla sunt ex occaecat reprehenderit commodo officia dolor Lorem duis laboris cupidatat officia voluptate. Culpa proident adipisicing id nulla nisi laboris ex in Lorem sunt duis officia eiusmod. Aliqua reprehenderit commodo ex non excepteur duis sunt velit enim. Voluptate laboris sint cupidatat ullamco ut ea consectetur et est culpa et culpa duis. diff --git a/go/nvim/luasnippets/go.lua b/go/nvim/luasnippets/go.lua deleted file mode 100644 index a1d42c4..0000000 --- a/go/nvim/luasnippets/go.lua +++ /dev/null @@ -1,10 +0,0 @@ -return { - parse( - { trig = 'func', name = 'Function' }, - 'func ${1:name}($2) $3{\n\t$4\n}' - ), - parse( - { trig = 'err', name = 'Handle error' }, - 'if ${2:err} != nil { return ${1}${2} }' - ), -} diff --git a/go/nvim/snippets/go.snippets b/go/nvim/snippets/go.snippets new file mode 100644 index 0000000..19afca5 --- /dev/null +++ b/go/nvim/snippets/go.snippets @@ -0,0 +1,6 @@ +snippet func + func ${1:name}(${2}) ${3}{ + ${0} + } +snippet err + if ${2:err} != nil { return ${1}${2} }