diff --git a/lua/lazyvim/plugins/coding.lua b/lua/lazyvim/plugins/coding.lua index c6571433..662977f0 100644 --- a/lua/lazyvim/plugins/coding.lua +++ b/lua/lazyvim/plugins/coding.lua @@ -1,35 +1,5 @@ return { - -- snippets - { - "L3MON4D3/LuaSnip", - build = (not jit.os:find("Windows")) - and "echo 'NOTE: jsregexp is optional, so not a big deal if it fails to build'; make install_jsregexp" - or nil, - dependencies = { - "rafamadriz/friendly-snippets", - config = function() - require("luasnip.loaders.from_vscode").lazy_load() - end, - }, - opts = { - history = true, - delete_check_events = "TextChanged", - }, - -- stylua: ignore - keys = { - { - "", - function() - return require("luasnip").jumpable(1) and "luasnip-jump-next" or "" - end, - expr = true, silent = true, mode = "i", - }, - { "", function() require("luasnip").jump(1) end, mode = "s" }, - { "", function() require("luasnip").jump(-1) end, mode = { "i", "s" } }, - }, - }, - -- auto completion { "hrsh7th/nvim-cmp", @@ -39,7 +9,6 @@ return { "hrsh7th/cmp-nvim-lsp", "hrsh7th/cmp-buffer", "hrsh7th/cmp-path", - "saadparwaiz1/cmp_luasnip", }, opts = function() vim.api.nvim_set_hl(0, "CmpGhostText", { link = "Comment", default = true }) @@ -49,11 +18,6 @@ return { completion = { completeopt = "menu,menuone,noinsert", }, - snippet = { - expand = function(args) - require("luasnip").lsp_expand(args.body) - end, - }, mapping = cmp.mapping.preset.insert({ [""] = cmp.mapping.select_next_item({ behavior = cmp.SelectBehavior.Insert }), [""] = cmp.mapping.select_prev_item({ behavior = cmp.SelectBehavior.Insert }), @@ -73,7 +37,6 @@ return { }), sources = cmp.config.sources({ { name = "nvim_lsp" }, - { name = "luasnip" }, { name = "path" }, }, { { name = "buffer" }, @@ -104,6 +67,52 @@ return { end, }, + -- snippets + { + "L3MON4D3/LuaSnip", + build = (not jit.os:find("Windows")) + and "echo 'NOTE: jsregexp is optional, so not a big deal if it fails to build'; make install_jsregexp" + or nil, + dependencies = { + { + "rafamadriz/friendly-snippets", + config = function() + require("luasnip.loaders.from_vscode").lazy_load() + end, + }, + { + "nvim-cmp", + dependencies = { + "saadparwaiz1/cmp_luasnip", + }, + opts = function(_, opts) + opts.snippet = { + expand = function(args) + require("luasnip").lsp_expand(args.body) + end, + } + table.insert(opts.sources, { name = "luasnip" }) + end, + }, + }, + opts = { + history = true, + delete_check_events = "TextChanged", + }, + -- stylua: ignore + keys = { + { + "", + function() + return require("luasnip").jumpable(1) and "luasnip-jump-next" or "" + end, + expr = true, silent = true, mode = "i", + }, + { "", function() require("luasnip").jump(1) end, mode = "s" }, + { "", function() require("luasnip").jump(-1) end, mode = { "i", "s" } }, + }, + }, + -- auto pairs { "echasnovski/mini.pairs", diff --git a/lua/lazyvim/plugins/extras/coding/native_snippets.lua b/lua/lazyvim/plugins/extras/coding/native_snippets.lua new file mode 100644 index 00000000..72080c92 --- /dev/null +++ b/lua/lazyvim/plugins/extras/coding/native_snippets.lua @@ -0,0 +1,59 @@ +return { + desc = "Use native snippets instead of LuaSnip. Only works on Neovim >= 0.10!", + { + "L3MON4D3/LuaSnip", + enabled = false, + }, + { + "nvim-cmp", + opts = { + snippet = { + expand = function(args) + vim.snippet.expand(args.body) + end, + }, + }, + keys = { + { + "", + function() + if vim.snippet.jumpable(1) then + vim.schedule(function() + vim.snippet.jump(1) + end) + return + end + return "" + end, + expr = true, + silent = true, + mode = "i", + }, + { + "", + function() + vim.schedule(function() + vim.snippet.jump(1) + end) + end, + silent = true, + mode = "s", + }, + { + "", + function() + if vim.snippet.jumpable(-1) then + vim.schedule(function() + vim.snippet.jump(-1) + end) + return + end + return "" + end, + expr = true, + silent = true, + mode = { "i", "s" }, + }, + }, + }, +}