diff --git a/nvim/.config/nvim/after/plugin/snipcomp.lua b/nvim/.config/nvim/after/plugin/snipcomp.lua deleted file mode 100644 index 87e5783..0000000 --- a/nvim/.config/nvim/after/plugin/snipcomp.lua +++ /dev/null @@ -1,63 +0,0 @@ ---[[ - Companion plugin for the LuaSnip snippet engine. Defines a completion - function which can be used for built-in insert mode completion (e.g. omni - completion). See 'ins-completion' for details. After completion the snippet - is expanded. - https://github.com/potamides/dotfiles/blob/master/.config/nvim/plugin/snipcomp.lua ---]] - --- lazy load LuaSnip, only useful when LuaSnip wasn't already loaded elsewhere -local luasnip = setmetatable({}, {__index = function(_, key) return require("luasnip")[key] end}) -vim.luasnip = {} - --- https://github.com/hrsh7th/nvim-cmp/issues/180#issuecomment-915405589 -require'luasnip'.config.set_config { history = true } -require('luasnip.loaders.from_vscode').lazy_load {} - -local function snippet2completion(snippet) - return { - word = snippet.trigger, - menu = snippet.name, - info = vim.trim(table.concat(vim.tbl_flatten({snippet.dscr or "", "", snippet:get_docstring()}), "\n")), - dup = true, - user_data = "luasnip" - } -end - -local function snippetfilter(line_to_cursor, base) - return function(s) - return not s.hidden and vim.startswith(s.trigger, base) and s.show_condition(line_to_cursor) - end -end - --- Set 'completefunc' or 'omnifunc' to 'v:lua.vim.luasnip.completefunc' to get --- completion. -function vim.luasnip.completefunc(findstart, base) - local line, col = vim.api.nvim_get_current_line(), vim.api.nvim_win_get_cursor(0)[2] - local line_to_cursor = line:sub(1, col) - - if findstart == 1 then - return vim.fn.match(line_to_cursor, '\\k*$') - end - - local snippets = vim.list_extend(vim.list_slice(luasnip.get_snippets("all")), luasnip.get_snippets(vim.bo.filetype)) - snippets = vim.tbl_filter(snippetfilter(line_to_cursor, base), snippets) - snippets = vim.tbl_map(snippet2completion, snippets) - table.sort(snippets, function(s1, s2) return s1.word < s2.word end) - return snippets -end - -function vim.luasnip.completion_expand(item) - if item.user_data == "luasnip" and luasnip.expandable() then - luasnip.expand() - end -end - -vim.cmd([[ - augroup luasnip_completion_expand - autocmd! - autocmd CompleteDone * call v:lua.vim.luasnip.completion_expand(v:completed_item) - augroup END -]]) - -vim.o.completefunc = 'v:lua.vim.luasnip.completefunc' diff --git a/nvim/.config/nvim/after/plugin/snippy.lua b/nvim/.config/nvim/after/plugin/snippy.lua new file mode 100644 index 0000000..0a51c19 --- /dev/null +++ b/nvim/.config/nvim/after/plugin/snippy.lua @@ -0,0 +1,19 @@ +local snippy_id = vim.api.nvim_create_augroup("snippy", { clear = true }) + +vim.api.nvim_create_autocmd("CompleteDone", { + group = snippy_id, + callback = function() + require("snippy").complete_done() + end, +}) + +require("snippy").setup({ + mappings = { + is = { + [""] = "next", + [""] = "previous", + }, + }, +}) + +vim.keymap.set('i', '', 'lua require(\'snippy\').complete()', { noremap = true, unique = true, silent = true }) diff --git a/nvim/.config/nvim/lua/plugins.lua b/nvim/.config/nvim/lua/plugins.lua index 3a5bb2a..3c47bf6 100644 --- a/nvim/.config/nvim/lua/plugins.lua +++ b/nvim/.config/nvim/lua/plugins.lua @@ -16,9 +16,9 @@ local init = function () use 'rmagatti/auto-session' -- Snippets use { - 'L3MON4D3/LuaSnip', + 'dcampos/nvim-snippy', requires = { - 'rafamadriz/friendly-snippets', + 'honza/vim-snippets', } } -- Git support