From 70ee28574e55adcf8d9ee958ac59b0191257b6c6 Mon Sep 17 00:00:00 2001 From: Vladan Popovic Date: Sun, 24 Sep 2023 01:19:07 +0200 Subject: [PATCH] replace compe with cmp --- lua/config/cmp.lua | 67 +++++++++++++++++++++++++++++++++++++ lua/config/compe.lua | 78 -------------------------------------------- lua/config/init.lua | 3 +- lua/plugins.lua | 2 +- plugin/compe.vim | 5 --- 5 files changed, 69 insertions(+), 86 deletions(-) create mode 100644 lua/config/cmp.lua delete mode 100644 lua/config/compe.lua delete mode 100644 plugin/compe.vim diff --git a/lua/config/cmp.lua b/lua/config/cmp.lua new file mode 100644 index 0000000..a3f5ee6 --- /dev/null +++ b/lua/config/cmp.lua @@ -0,0 +1,67 @@ +-- Completion plugin config + +local utils = require('utils') + +vim.cmd [[set shortmess+=c]] +utils.opt('o', 'completeopt', 'menuone,noselect') + +local cmp = require('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, + }, + window = { + -- completion = cmp.config.window.bordered(), + -- documentation = cmp.config.window.bordered(), + }, + 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. + }), + sources = cmp.config.sources({ + { name = 'nvim_lsp' }, + { name = 'vsnip' }, -- For vsnip users. + -- { name = 'luasnip' }, -- For luasnip users. + -- { name = 'ultisnips' }, -- For ultisnips users. + -- { name = 'snippy' }, -- For snippy users. + }, { + { name = 'buffer' }, + }) +}) + +-- 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 = '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' } + } +}) + +-- 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' } + }) +}) diff --git a/lua/config/compe.lua b/lua/config/compe.lua deleted file mode 100644 index 1f711a3..0000000 --- a/lua/config/compe.lua +++ /dev/null @@ -1,78 +0,0 @@ --- Configuration for nvim-compe - -local utils = require('utils') - -vim.cmd [[set shortmess+=c]] -utils.opt('o', 'completeopt', 'menuone,noselect') - -require'compe'.setup { - enabled = true; - autocomplete = false; - debug = false; - min_length = 1; - preselect = 'enable'; - throttle_time = 80; - source_timeout = 200; - incomplete_delay = 400; - allow_prefix_unmatch = false; - max_abbr_width = 1000; - max_kind_width = 1000; - max_menu_width = 1000000; - documentation = false; - - - source = { - path = true; - buffer = true; - calc = true; - vsnip = true; - nvim_lsp = true; - nvim_lua = true; - spell = true; - tags = true; - snippets_nvim = true; - treesitter = true; - }; -} - -local t = function(str) - return vim.api.nvim_replace_termcodes(str, true, true, true) -end - -local check_back_space = function() - local col = vim.fn.col('.') - 1 - if col == 0 or vim.fn.getline('.'):sub(col, col):match('%s') then - return true - else - return false - end -end - --- Use (s-)tab to: ---- move to prev/next item in completion menuone ---- jump to prev/next snippet's placeholder --- _G.tab_complete = function() --- if vim.fn.pumvisible() == 1 then --- return t "" --- elseif vim.fn.call("vsnip#available", {1}) == 1 then --- return t "(vsnip-expand-or-jump)" --- elseif check_back_space() then --- return t "" --- else --- return vim.fn['compe#complete']() --- end --- end --- _G.s_tab_complete = function() --- if vim.fn.pumvisible() == 1 then --- return t "" --- elseif vim.fn.call("vsnip#jumpable", {-1}) == 1 then --- return t "(vsnip-jump-prev)" --- else --- return t "" --- end --- end - --- utils.map("i", "", "v:lua.tab_complete()", {expr = true}) --- utils.map("s", "", "v:lua.tab_complete()", {expr = true}) --- utils.map("i", "", "v:lua.s_tab_complete()", {expr = true}) --- utils.map("s", "", "v:lua.s_tab_complete()", {expr = true}) diff --git a/lua/config/init.lua b/lua/config/init.lua index 960b7cc..90e69d7 100644 --- a/lua/config/init.lua +++ b/lua/config/init.lua @@ -1,4 +1,3 @@ --- nvim-compe -require('config.compe') +require('config.cmp') require('config.treesitter') require('config.telescope') diff --git a/lua/plugins.lua b/lua/plugins.lua index e325bb1..dda78c5 100644 --- a/lua/plugins.lua +++ b/lua/plugins.lua @@ -112,7 +112,7 @@ return require('packer').startup(function() use { 'cespare/vim-toml' } use { 'folke/trouble.nvim' } - use { 'hrsh7th/nvim-compe' } + use { 'hrsh7th/nvim-cmp' } use { 'jacoborus/tender.vim' } use { 'RRethy/vim-illuminate' } use { 'rust-lang/rust.vim' } diff --git a/plugin/compe.vim b/plugin/compe.vim deleted file mode 100644 index 2503d85..0000000 --- a/plugin/compe.vim +++ /dev/null @@ -1,5 +0,0 @@ -inoremap compe#complete() -inoremap compe#confirm('') -inoremap compe#close('') -inoremap compe#scroll({ 'delta': +4 }) -inoremap compe#scroll({ 'delta': -4 })