nvim: Switch deprecated nvim-compe

Switched out the deprecated nvim-compe for nvim-cmp and re-added most of
the plugins that the earlier one supported.

The handling is very similar and it supports the same snippet engine
(vsnip in this case).
This commit is contained in:
Marty Oehme 2021-12-15 10:31:11 +01:00
parent 333e2580f0
commit e64df2ec3d
Signed by: Marty
GPG key ID: B7538B8F50A1C800
4 changed files with 118 additions and 46 deletions

View file

@ -1,8 +1,4 @@
require('nvim-autopairs').setup({check_ts = true}) require('nvim-autopairs').setup({check_ts = true})
require("nvim-autopairs.completion.compe").setup({
map_cr = true, -- map <CR> on insert mode
map_complete = true -- it will auto insert `(` after select function or method item
})
--- Auto-space rules --- Auto-space rules
local npairs = require 'nvim-autopairs' local npairs = require 'nvim-autopairs'
@ -14,3 +10,9 @@ npairs.add_rules {
return vim.tbl_contains({'()', '[]', '{}'}, pair) return vim.tbl_contains({'()', '[]', '{}'}, pair)
end) end)
} }
local cmp_autopairs = require('nvim-autopairs.completion.cmp')
local cmp = require('cmp')
cmp.event:on('confirm_done',
cmp_autopairs.on_confirm_done({map_char = {tex = ''}}))
-- add a lisp filetype (wrap my-function), FYI: Hardcoded = { "clojure", "clojurescript", "fennel", "janet" }
cmp_autopairs.lisp[#cmp_autopairs.lisp + 1] = "racket"

View file

@ -1,14 +1,11 @@
-- Settings for indentBlankline -- Settings for indentBlankline
-- turn off for diff views since we want to compare directly -- turn off for diff views since we want to compare directly
if vim.wo.diff then if vim.wo.diff then vim.g["indent_blankline_enabled"] = false end
vim.g["indent_blankline_enabled"] = false
end
vim.g.indent_blankline_char = "" vim.g.indent_blankline_char = ""
vim.g.indent_blankline_filetype_exclude = { vim.g.indent_blankline_filetype_exclude = {
"help", "undotree", "help", "undotree", "markdown", "text", "pandoc", "rst", "asciidoc",
"markdown", "text", "pandoc", "rst", "asciidoc",
"vim-plug" "vim-plug"
} }
vim.g.indent_blankline_buftype_exclude = {"terminal"} vim.g.indent_blankline_buftype_exclude = {"terminal"}

View file

@ -2,7 +2,23 @@ local api = vim.api
local saga = require 'lspsaga' local saga = require 'lspsaga'
local lspcfg = require 'lspconfig' local lspcfg = require 'lspconfig'
local compe = require 'compe' local cmp = require 'cmp'
local lspkind = require 'lspkind'
require"lsp_signature".setup()
local has_words_before = function()
local line, col = unpack(vim.api.nvim_win_get_cursor(0))
return col ~= 0 and
vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col,
col)
:match("%s") == nil
end
local feedkey = function(key, mode)
vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes(key, true, true, true),
mode, true)
end
-- Enable the following language servers -- Enable the following language servers
local servers = { local servers = {
@ -10,35 +26,77 @@ local servers = {
-- sumneko_lua further down, needs more setup -- sumneko_lua further down, needs more setup
} }
vim.o.completeopt = "menuone,noselect" vim.o.completeopt = "menu,menuone,noselect"
-- completion sources, higher priority = closer to the top?
compe.setup({ -- completion items
source = { require('cmp').register_source('vCard', require('completion_vcard').setup_cmp(
nvim_lsp = {kind = ""}, '~/documents/contacts/myconts'))
nvim_treesitter = {kind = ""}, vim.g.vsnip_snippet_dir = (vim.env.XDG_DATA_HOME or "~/.local/share") ..
buffer = {kind = ""}, "/nvim/snippets"
path = {kind = ""}, cmp.setup({
calc = {kind = ""}, snippet = {expand = function(args) vim.fn["vsnip#anonymous"](args.body) end},
nvim_lua = true, mapping = {
emoji = { ['<C-b>'] = cmp.mapping(cmp.mapping.scroll_docs(-4), {'i', 'c'}),
kind = "", ['<C-f>'] = cmp.mapping(cmp.mapping.scroll_docs(4), {'i', 'c'}),
filetypes = {"markdown", "text", "pandoc", "rst", "asciidoc"} ['<C-Space>'] = cmp.mapping(cmp.mapping.complete(), {'i', 'c'}),
}, ['<C-y>'] = cmp.config.disable, -- Specify `cmp.config.disable` if you want to remove the default `<C-y>` mapping.
latex_symbols = { ['<C-e>'] = cmp.mapping({
kind = "λ", i = cmp.mapping.abort(),
filetypes = {"markdown", "text", "pandoc", "rst", "asciidoc"} c = cmp.mapping.close()
}, }),
tmux = {kind = "τ"}, -- Accept currently selected item. If none selected, `select` first item.
spell = {kind = "", priority = 0}, -- Set `select` to `false` to only confirm explicitly selected items.
vsnip = true ['<CR>'] = cmp.mapping.confirm({select = false}),
} ["<C-n>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_next_item()
elseif vim.fn["vsnip#available"](1) == 1 then
feedkey("<Plug>(vsnip-expand-or-jump)", "")
elseif has_words_before() then
cmp.complete()
else
fallback()
end
end, {"i", "s"}),
["<C-p>"] = cmp.mapping(function()
if cmp.visible() then
cmp.select_prev_item()
elseif vim.fn["vsnip#jumpable"](-1) == 1 then
feedkey("<Plug>(vsnip-jump-prev)", "")
end
end, {"i", "s"})
},
formatting = {
format = lspkind.cmp_format({
with_text = false,
menu = ({
buffer = "B",
nvim_lua = "NLua",
tmux = "τ",
vCard = "VCARD"
})
})
},
sources = cmp.config.sources({
{name = 'path'}, {name = 'nvim_lsp'}, {name = 'treesitter'},
{name = 'tmux'}, {name = 'vsnip'}, {name = 'latex_symbols'},
{name = 'pandoc_references'}, {name = 'vCard'}
}, {{name = 'buffer'}, {name = 'spell'}})
}) })
local capabilities = vim.lsp.protocol.make_client_capabilities() -- Use buffer source for `/` search
capabilities.textDocument.completion.completionItem.snippetSupport = true cmp.setup.cmdline('/', {sources = {{name = 'buffer'}}})
capabilities.textDocument.completion.completionItem.resolveSupport = {
properties = {'documentation', 'detail', 'additionalTextEdits'} -- Use cmdline & path source for ':' in vim
} cmp.setup.cmdline(':', {
sources = cmp.config.sources({{name = 'path'}}, {{name = 'cmdline'}})
})
-- Setup lspconfig.
local capabilities = require('cmp_nvim_lsp').update_capabilities(vim.lsp
.protocol
.make_client_capabilities())
local on_attach = function(_, _) local on_attach = function(_, _)
-- Keybindings for LSPs -- Keybindings for LSPs
@ -109,7 +167,9 @@ local on_attach = function(_, _)
end end
-- set up simple servers -- set up simple servers
for _, lsp in ipairs(servers) do lspcfg[lsp].setup {on_attach = on_attach} end for _, lsp in ipairs(servers) do
lspcfg[lsp].setup {on_attach = on_attach, capabilities = capabilities}
end
lspcfg.efm.setup { lspcfg.efm.setup {
on_attach = on_attach, on_attach = on_attach,

View file

@ -26,9 +26,10 @@ require("packer").startup(function()
use 'jeffkreeftmeijer/vim-numbertoggle' -- toggles numbers to absolute for all buffers but the current which is relative use 'jeffkreeftmeijer/vim-numbertoggle' -- toggles numbers to absolute for all buffers but the current which is relative
use 'RRethy/vim-illuminate' -- highlight other occurences of the word under cursor use 'RRethy/vim-illuminate' -- highlight other occurences of the word under cursor
use 'ggandor/lightspeed.nvim' -- jump between letters with improved fFtT quicksearch, mimics sneak use 'ggandor/lightspeed.nvim' -- jump between letters with improved fFtT quicksearch, mimics sneak
use 'lukas-reineke/indent-blankline.nvim' -- show a vertical line for each indentation -- use { -- weird errors currently
require('plug._indent-blankline') -- 'lukas-reineke/indent-blankline.nvim', -- show a vertical line for each indentation
-- config = function() require('plug._indent-blankline') end
-- }
-- files -- files
use 'vifm/vifm.vim' -- integrate file manager use 'vifm/vifm.vim' -- integrate file manager
use { use {
@ -125,7 +126,6 @@ require("packer").startup(function()
-- --
-- nvim plugs -- nvim plugs
use 'Iron-E/nvim-cartographer' -- makes it easier to set mappings through lua use 'Iron-E/nvim-cartographer' -- makes it easier to set mappings through lua
use 'marty-oehme/zettelkasten.nvim' -- simple static markdown linking use 'marty-oehme/zettelkasten.nvim' -- simple static markdown linking
use { use {
@ -145,12 +145,21 @@ require("packer").startup(function()
-- lsp -- lsp
use 'neovim/nvim-lspconfig' -- some commong language server configurations use 'neovim/nvim-lspconfig' -- some commong language server configurations
use 'tami5/lspsaga.nvim' -- nice and fast ui for lsp actions use 'tami5/lspsaga.nvim' -- nice and fast ui for lsp actions WILL HAVE TO BE REPLACED SOON
use 'simrat39/symbols-outline.nvim' -- vista-like outline view for code use 'simrat39/symbols-outline.nvim' -- vista-like outline view for code
use 'ray-x/lsp_signature.nvim'
-- and completion -- and completion
use 'hrsh7th/nvim-compe' -- simple completion engine built specifically for nvim and lsp use {
use 'GoldsteinE/compe-latex-symbols' -- adding unicode symbols for latex (/pandoc) files 'hrsh7th/nvim-cmp', -- simple completion engine built specifically for nvim and lsp
use {'andersevenrud/compe-tmux', branch = 'compe' } -- completion source from adjacent tmux panes requires = {
'onsails/lspkind-nvim', 'andersevenrud/cmp-tmux', -- completion source from adjacent tmux panes
'hrsh7th/cmp-nvim-lsp', 'hrsh7th/cmp-buffer', 'hrsh7th/cmp-path',
'hrsh7th/cmp-cmdline', 'hrsh7th/cmp-vsnip',
'kdheepak/cmp-latex-symbols', 'ray-x/cmp-treesitter',
'f3fora/cmp-spell', 'jc-doyle/cmp-pandoc-references',
'cbarrete/completion-vcard'
}
}
-- snippeting -- snippeting
use {"hrsh7th/vim-vsnip", event = "InsertEnter"} -- snippet engine use {"hrsh7th/vim-vsnip", event = "InsertEnter"} -- snippet engine
use {"rafamadriz/friendly-snippets", event = "InsertEnter"} -- many snippets use {"rafamadriz/friendly-snippets", event = "InsertEnter"} -- many snippets
@ -181,5 +190,9 @@ require("packer").startup(function()
} }
use 'p00f/nvim-ts-rainbow' -- rainbow brackets using treesitter use 'p00f/nvim-ts-rainbow' -- rainbow brackets using treesitter
use 'JoosepAlviste/nvim-ts-context-commentstring' -- improves commenting plugin above by using ts use 'JoosepAlviste/nvim-ts-context-commentstring' -- improves commenting plugin above by using ts
use {
'lewis6991/spellsitter.nvim', -- uses treesitter to highlight spelling errors
config = function() require('spellsitter').setup() end
}
end) end)