diff --git a/nvim/init.lua b/nvim/init.lua index 3b5e55b..9c76349 100644 --- a/nvim/init.lua +++ b/nvim/init.lua @@ -6,8 +6,9 @@ require('pluginoptions') -- PLUGIN OPTIONS require('telescopeconfig') +require('statusline') +require('snippets') require('autocompletion') require('treesitterconfig') require('filemanager') -require('statusline') require('notes') diff --git a/nvim/lua/autocompletion.lua b/nvim/lua/autocompletion.lua index 04a5746..ade1dc5 100644 --- a/nvim/lua/autocompletion.lua +++ b/nvim/lua/autocompletion.lua @@ -1,15 +1,17 @@ -- Setup nvim-cmp. -local cmp = require'cmp' +local cmp = require 'cmp' cmp.setup({ snippet = { expand = function(args) - vim.fn['UltiSnips#Anon'](args.body) -- For `ultisnips` users. + require('luasnip').lsp_expand(args.body) end, }, mapping = { [''] = cmp.mapping(cmp.mapping.scroll_docs(-4), { 'i', 'c' }), [''] = cmp.mapping(cmp.mapping.scroll_docs(4), { 'i', 'c' }), + [''] = cmp.mapping(cmp.mapping.select_next_item(), {'i','c'}), + [''] = cmp.mapping(cmp.mapping.select_prev_item(), {'i','c'}), [''] = cmp.mapping(cmp.mapping.complete(), { 'i', 'c' }), [''] = cmp.config.disable, -- Specify `cmp.config.disable` if you want to remove the default `` mapping. [''] = cmp.mapping({ @@ -22,6 +24,7 @@ cmp.setup({ }, sources = cmp.config.sources({ { name = 'nvim_lsp' }, + { name = 'luasnip' }, }, { { name = 'buffer' }, }) diff --git a/nvim/lua/plugins.lua b/nvim/lua/plugins.lua index ca74a02..c1d47bb 100644 --- a/nvim/lua/plugins.lua +++ b/nvim/lua/plugins.lua @@ -76,8 +76,8 @@ Plug 'hrsh7th/cmp-path' Plug 'hrsh7th/cmp-cmdline' Plug 'hrsh7th/nvim-cmp' -Plug 'SirVer/ultisnips' -Plug 'quangnguyen30192/cmp-nvim-ultisnips' +Plug 'L3MON4D3/LuaSnip' +Plug 'saadparwaiz1/cmp_luasnip' -- Autoformatter Plug 'sbdchd/neoformat' diff --git a/nvim/lua/snippets.lua b/nvim/lua/snippets.lua new file mode 100644 index 0000000..3fbc0ab --- /dev/null +++ b/nvim/lua/snippets.lua @@ -0,0 +1,56 @@ +local ls = require "luasnip" + +local types = require "luasnip.util.types" + +ls.config.set_config { + history = true, + updateevents = "TextChanged,TextChangedI", + + enable_autosnippets = true, + + ext_opts = { + [types.choiceNode] = { + active = { + virt_text = { { "<-", "Error" } }, + } + } + }, +} + +-- expand snippet / jump to next location +vim.keymap.set({"i", "s" }, "", function() + if ls.expand_or_jumpable() then + ls.expand_or_jump() + end +end, { silent = true }) + +-- jump to previous location +vim.keymap.set({"i", "s" }, "", function() + if ls.jumpable(-1) then + ls.jump(-1) + end +end, { silent = true }) + +-- jump to previous location +vim.keymap.set({"i"}, "", function() + if ls.choice_active() then + ls.change_choice(1) + end +end, { silent = true }) + +-- source luafile again +vim.keymap.set("n", "s", "source ~/.config/nvim/lua/snippets.lua") + +local s = ls.s +local i = ls.insert_node +local rep = require("luasnip.extras").rep +local fmt = require("luasnip.extras.fmt").fmt + + +ls.add_snippets("tex", { + s("beg", fmt([[ +\begin{<>} + <> +\end{<>} + ]], {i(1, "itemize"), i(2, "test"), rep(1)}, {delimiters = "<>"})), +})