1
0
mirror of https://github.com/jdhao/nvim-config.git synced 2025-06-08 14:14:33 +02:00

transition from nvim-compe to nvim-cmp

This commit is contained in:
jdhao
2021-10-18 21:56:32 +08:00
parent a603ce3e4d
commit e2bcb7d8f4
4 changed files with 56 additions and 43 deletions

View File

@@ -1,38 +0,0 @@
-- nvim-compe settings
require("compe").setup({
enabled = true,
autocomplete = true,
debug = false,
min_length = 1,
preselect = "enable",
throttle_time = 80,
source_timeout = 200,
incomplete_delay = 400,
max_abbr_width = 100,
max_kind_width = 100,
max_menu_width = 100,
documentation = true,
source = {
omni = { filetypes = { "tex" } },
path = true,
buffer = false,
spell = { filetypes = { "markdown", "tex" } },
emoji = true,
nvim_lsp = true,
nvim_lua = true,
ultisnips = true,
calc = false,
vsnip = false,
},
})
vim.o.completeopt = "menuone,noselect"
-- nvim-compe mappings
local compe_map_opts = { expr = true, noremap = true, silent = true }
vim.api.nvim_set_keymap("i", "<C-Space>", "compe#complete()", compe_map_opts)
vim.api.nvim_set_keymap("i", "<CR>", "compe#confirm('<CR>')", compe_map_opts)
vim.api.nvim_set_keymap("i", "<ESC>", "compe#close('<ESC>')", compe_map_opts)
vim.api.nvim_set_keymap("i", "<C-f>", "compe#scroll({'delta': +4})", compe_map_opts)
vim.api.nvim_set_keymap("i", "<C-d>", "compe#scroll({'delta': -4})", compe_map_opts)

View File

@@ -66,7 +66,7 @@ local custom_attach = function(client, bufnr)
-- vim.notify(msg, 'info', {title = 'Nvim-config', timeout = 2500})
end
local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities = require('cmp_nvim_lsp').update_capabilities(vim.lsp.protocol.make_client_capabilities())
capabilities.textDocument.completion.completionItem.snippetSupport = true
local lspconfig = require("lspconfig")
@@ -88,10 +88,12 @@ lspconfig.pylsp.setup({
flags = {
debounce_text_changes = 200,
},
capabilities = capabilities,
})
-- lspconfig.pyright.setup{
-- on_attach = custom_attach,
-- capabilities = capabilities
-- }
lspconfig.clangd.setup({
@@ -109,6 +111,7 @@ lspconfig.vimls.setup({
flags = {
debounce_text_changes = 500,
},
capabilities = capabilities,
})
local sumneko_binary_path = vim.fn.exepath("lua-language-server")
@@ -144,6 +147,7 @@ if vim.g.is_mac or vim.g.is_linux and sumneko_binary_path ~= "" then
},
},
},
capabilities = capabilities,
})
end

41
lua/config/nvim-cmp.lua Normal file
View File

@@ -0,0 +1,41 @@
-- Setup nvim-cmp.
local cmp = require'cmp'
cmp.setup({
snippet = {
expand = function(args)
-- For `ultisnips` user.
vim.fn["UltiSnips#Anon"](args.body)
end,
},
mapping = {
['<Tab>'] = function(fallback)
if cmp.visible() then
cmp.select_next_item()
else
fallback()
end
end,
['<S-Tab>'] = function(fallback)
if cmp.visible() then
cmp.select_prev_item()
else
fallback()
end
end,
['<Esc>'] = cmp.mapping.close(),
},
sources = {
{ name = 'nvim_lsp' }, -- For nvim-lsp
{ name = 'ultisnips' }, -- For ultisnips user.
{ name = 'path' }, -- for path completion
{ name = 'emoji', insert = true, } -- emoji completion
},
completion = {
keyword_length = 1,
completeopt = "menu,menuone,noinsert"
},
experimental = {
ghost_text = false
}
})