From bae5eb0cfdb605679c40c5200e1ada98fd09ba4a Mon Sep 17 00:00:00 2001 From: SinTan1729 Date: Mon, 25 Mar 2024 13:44:31 -0500 Subject: [PATCH] chg: Switch to cmp-vimtex --- laptop/plugin/autopairs.lua | 45 ++++++++++---------- laptop/plugin/cmp.lua | 84 ++++++++++++++++++------------------- laptop/plugins.lua | 2 +- 3 files changed, 66 insertions(+), 65 deletions(-) diff --git a/laptop/plugin/autopairs.lua b/laptop/plugin/autopairs.lua index 05ca743..8ef1245 100644 --- a/laptop/plugin/autopairs.lua +++ b/laptop/plugin/autopairs.lua @@ -8,11 +8,11 @@ npairs.setup({ }) npairs.add_rules({ - Rule("\\(", "\\)", {"tex", "latex"}), - Rule("\\[", "\\]", {"tex", "latex"}), + Rule("\\(", "\\)", { "tex", "latex" }), + Rule("\\[", "\\]", { "tex", "latex" }), }, -- disable for .vim files, but it work for another filetypes - Rule("a","a","-vim") + Rule("a", "a", "-vim") ) -- Add spaces between brackets @@ -20,7 +20,7 @@ local brackets = { { '(', ')' }, { '[', ']' }, { '{', '}' } } npairs.add_rules { -- Rule for a pair with left-side ' ' and right side ' ' Rule(' ', ' ') - -- Pair will only occur if the conditional function returns true + -- Pair will only occur if the conditional function returns true :with_pair(function(opts) -- We are checking if we are inserting a space in (), [], or {} local pair = opts.line:sub(opts.col - 1, opts.col) @@ -32,7 +32,7 @@ npairs.add_rules { end) :with_move(cond.none()) :with_cr(cond.none()) - -- We only want to delete the pair of spaces when the cursor is as such: ( | ) + -- We only want to delete the pair of spaces when the cursor is as such: ( | ) :with_del(function(opts) local col = vim.api.nvim_win_get_cursor(0)[2] local context = opts.line:sub(col - 1, col + 2) @@ -52,14 +52,14 @@ for _, bracket in pairs(brackets) do :with_move(function(opts) return opts.char == bracket[2] end) :with_del(cond.none()) :use_key(bracket[2]) - -- Removes the trailing whitespace that can occur without this + -- Removes the trailing whitespace that can occur without this :replace_map_cr(function(_) return '2xiO' end) } end -- Add space around = npairs.add_rules { - Rule('=', '', { "-tex", "-vim", "-sh" }) + Rule('=', '', { "-tex", "-vim", "-sh", "-dockerfile" }) :with_pair(cond.not_inside_quote()) :with_pair(function(opts) local last_char = opts.line:sub(opts.col - 1, opts.col - 1) @@ -89,20 +89,21 @@ npairs.add_rules { } -- Insertion with surrounding check -function rule2(a1,ins,a2,lang) - npairs.add_rule( - Rule(ins, ins, lang) - :with_pair(function(opts) return a1..a2 == opts.line:sub(opts.col - #a1, opts.col + #a2 - 1) end) - :with_move(cond.none()) - :with_cr(cond.none()) - :with_del(function(opts) - local col = vim.api.nvim_win_get_cursor(0)[2] - return a1..ins..ins..a2 == opts.line:sub(col - #a1 - #ins + 1, col + #ins + #a2) -- insert only works for #ins == 1 anyway - end) - ) +function rule2(a1, ins, a2, lang) + npairs.add_rule( + Rule(ins, ins, lang) + :with_pair(function(opts) return a1 .. a2 == opts.line:sub(opts.col - #a1, opts.col + #a2 - 1) end) + :with_move(cond.none()) + :with_cr(cond.none()) + :with_del(function(opts) + local col = vim.api.nvim_win_get_cursor(0)[2] + return a1 .. ins .. ins .. a2 == + opts.line:sub(col - #a1 - #ins + 1, col + #ins + #a2) -- insert only works for #ins == 1 anyway + end) + ) end --- Only use it for ocaml -rule2('(','*',')','ocaml') -rule2('(*',' ','*)','ocaml') -rule2('(',' ',')') +-- Only use it for ocaml +rule2('(', '*', ')', 'ocaml') +rule2('(*', ' ', '*)', 'ocaml') +rule2('(', ' ', ')') diff --git a/laptop/plugin/cmp.lua b/laptop/plugin/cmp.lua index 97a58d8..ba1dcb5 100644 --- a/laptop/plugin/cmp.lua +++ b/laptop/plugin/cmp.lua @@ -3,70 +3,70 @@ local cmp_autopairs = require('nvim-autopairs.completion.cmp') cmp.setup({ snippet = { - -- REQUIRED - you must specify a snippet engine - expand = function(args) - -- vim.fn["vsnip#anonymous"](args.body) -- For `vsnip` users. - -- require('luasnip').lsp_expand(args.body) -- For `luasnip` users. - -- require('snippy').expand_snippet(args.body) -- For `snippy` users. - vim.fn["UltiSnips#Anon"](args.body) -- For `ultisnips` users. - end, + -- REQUIRED - you must specify a snippet engine + expand = function(args) + -- vim.fn["vsnip#anonymous"](args.body) -- For `vsnip` users. + -- require('luasnip').lsp_expand(args.body) -- For `luasnip` users. + -- require('snippy').expand_snippet(args.body) -- For `snippy` users. + vim.fn["UltiSnips#Anon"](args.body) -- For `ultisnips` users. + end, }, window = { - completion = cmp.config.window.bordered(winhighlight), - documentation = cmp.config.window.bordered(winhighlight), + completion = cmp.config.window.bordered(winhighlight), + documentation = cmp.config.window.bordered(winhighlight), }, mapping = cmp.mapping.preset.insert({ - [''] = cmp.mapping.scroll_docs(-4), - [''] = cmp.mapping.scroll_docs(4), - [''] = cmp.mapping.complete(), - [''] = cmp.mapping.abort(), - [''] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items. + [''] = cmp.mapping.scroll_docs(-4), + [''] = cmp.mapping.scroll_docs(4), + [''] = cmp.mapping.complete(), + [''] = cmp.mapping.abort(), + [''] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items. }), sources = cmp.config.sources({ - { name = 'nvim_lsp' }, - { name = "omni" }, - -- { name = 'vsnip' }, -- For vsnip users. - -- { name = 'luasnip' }, -- For luasnip users. - { name = 'ultisnips' }, -- For ultisnips users. - -- { name = 'snippy' }, -- For snippy users. - }, {{ name = 'buffer' }} + { name = 'nvim_lsp' }, + { name = "vimtex" }, + -- { name = 'vsnip' }, -- For vsnip users. + -- { name = 'luasnip' }, -- For luasnip users. + { name = 'ultisnips' }, -- For ultisnips users. + -- { name = 'snippy' }, -- For snippy users. + }, { { name = 'buffer' } } ), experimental = { ghost_text = true }, - }) +}) - -- Set configuration for specific filetype. - cmp.setup.filetype('gitcommit', { +-- Set configuration for specific filetype. +cmp.setup.filetype('gitcommit', { sources = cmp.config.sources({ - { name = 'git' }, -- You can specify the `git` source if [you were installed it](https://github.com/petertriho/cmp-git). + { name = 'git' }, -- You can specify the `git` source if [you were installed it](https://github.com/petertriho/cmp-git). }, { - { name = 'buffer' }, + { name = 'buffer' }, }) }) -- Use buffer source for `/` and `?` (if you enabled `native_menu`, this won't work anymore). cmp.setup.cmdline({ '/', '?' }, { -mapping = cmp.mapping.preset.cmdline(), -sources = { - { name = 'buffer' } -} + mapping = cmp.mapping.preset.cmdline(), + sources = { + { name = 'buffer' } + } }) -- Use cmdline & path source for ':' (if you enabled `native_menu`, this won't work anymore). cmp.setup.cmdline(':', { -mapping = cmp.mapping.preset.cmdline(), -sources = cmp.config.sources({ - { name = 'path' } -}, { - { name = 'cmdline' } -}) + mapping = cmp.mapping.preset.cmdline(), + sources = cmp.config.sources({ + { name = 'path' } + }, { + { name = 'cmdline' } + }) }) -- Insert `(` after select function or method item cmp.event:on( - 'confirm_done', - cmp_autopairs.on_confirm_done({ - filetypes = { - tex = false - } - }) + 'confirm_done', + cmp_autopairs.on_confirm_done({ + filetypes = { + tex = false + } + }) ) diff --git a/laptop/plugins.lua b/laptop/plugins.lua index f5a3592..cccfd0a 100644 --- a/laptop/plugins.lua +++ b/laptop/plugins.lua @@ -34,7 +34,7 @@ require("lazy").setup({ dependencies = { "hrsh7th/cmp-nvim-lsp", "hrsh7th/cmp-buffer", - "hrsh7th/cmp-omni", -- For LaTeX completion + "micangl/cmp-vimtex", "hrsh7th/cmp-path", "hrsh7th/cmp-cmdline", }