From c1445e28dc9f673e88d8a53b94f7559fa46b0eea Mon Sep 17 00:00:00 2001 From: Daniel Lundin Date: Sun, 9 Jan 2022 21:30:19 +0100 Subject: [PATCH] nvim-cmp deprecates nvim-compe --- .config/nvim/lua/plugins.lua | 113 ++++++++++++++++++++++++----------- 1 file changed, 78 insertions(+), 35 deletions(-) diff --git a/.config/nvim/lua/plugins.lua b/.config/nvim/lua/plugins.lua index 0cf19fa..0d3eab0 100644 --- a/.config/nvim/lua/plugins.lua +++ b/.config/nvim/lua/plugins.lua @@ -5,6 +5,7 @@ return require('packer').startup(function() use 'wbthomason/packer.nvim' use 'ray-x/lsp_signature.nvim' use 'jose-elias-alvarez/nvim-lsp-ts-utils' + use 'L3MON4D3/LuaSnip' use { 'b3nj5m1n/kommentary', @@ -20,43 +21,85 @@ return require('packer').startup(function() } use { - "hrsh7th/nvim-compe", - config = function() - require("compe").setup { - min_length = 0, - source = { - buffer = true, - nvim_lsp = true, - nvim_lua = true, - } - } - local utils = require("dln.utils") - local check_behind = function() - local is_empty = function(col) - return col <= 0 or vim.fn.getline("."):sub(col, col):match("%s") - end - local pos_col = vim.fn.col(".") - 1 - return is_empty(pos_col) and is_empty(pos_col - 1) and true or false - end + 'hrsh7th/nvim-cmp', + requires = { + 'andersevenrud/cmp-tmux', + 'hrsh7th/cmp-nvim-lsp', + 'hrsh7th/cmp-buffer', + 'hrsh7th/cmp-path', + 'hrsh7th/cmp-cmdline', + 'saadparwaiz1/cmp_luasnip', + }, + config = function() + local cmp = require'cmp' + -- local cmp = require('hrsh7th/nvim-cmp') - _G.complete = function(pum, empty) - if vim.fn.pumvisible() == 1 then - return utils.term_codes(pum) - elseif check_behind() then - return utils.term_codes(empty) - else - return vim.fn["compe#complete"]() - end - end + 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, + }, + + + mapping = { + [""] = cmp.mapping.scroll_docs(-4), + [""] = cmp.mapping.scroll_docs(4), + [""] = cmp.mapping.close(), + [""] = cmp.mapping.confirm({ + select = false, + }), + [''] = cmp.mapping(cmp.mapping.complete(), { 'i', 'c' }), + [""] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_next_item() + elseif luasnip.expand_or_jumpable() then + luasnip.expand_or_jump() + elseif has_words_before() then + cmp.complete() + else + fallback() + end + end, { "i", "s" }), + [""] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_prev_item() + elseif luasnip.jumpable(-1) then + luasnip.jump(-1) + else + fallback() + end + end, { "i", "s" }), + }, + + sources = cmp.config.sources({ + { + name = 'buffer', + priority = 1, + + }, + { name = 'luasnip' }, + { + name = 'tmux', + priority = 2, + option = { + trigger_characters = {}, + } + }, + { + name = 'nvim_lsp', + priority = 3, + }, + }) + }) + + end + } - utils.mapx("is", "", "v:lua.complete('', '')") - utils.mapx("is", "", "v:lua.complete('', '')") - utils.mapx("is", "", "v:lua.complete('', '')") - utils.mapx("is", "", "v:lua.complete('', '')") - utils.mapx("x", "", "compe:#confirm('", "compe#close('')") - end - } use { 'lewis6991/gitsigns.nvim',