From d2824f7ea91a0297a4ed2b35af4e38bdc0d04faa Mon Sep 17 00:00:00 2001 From: Johannes Stoelp Date: Wed, 20 Apr 2022 22:00:01 +0200 Subject: nvim: replace deprecated nvim-compe with nvim-cmp --- nvim.init.vim | 106 ++++++++++++++++++++++++++++++++++------------------------ 1 file changed, 63 insertions(+), 43 deletions(-) diff --git a/nvim.init.vim b/nvim.init.vim index 2cf7af6..399094d 100644 --- a/nvim.init.vim +++ b/nvim.init.vim @@ -11,9 +11,20 @@ call plug#begin('~/.nvim/plugged') " Colors. Plug 'chriskempson/base16-vim' - " LSP & Completion. + " vsnip manager. + Plug 'hrsh7th/vim-vsnip' + + " LSP. Plug 'neovim/nvim-lspconfig' - Plug 'hrsh7th/nvim-compe' + " Completion framework. + Plug 'hrsh7th/nvim-cmp' + " Completion sources. + Plug 'hrsh7th/cmp-vsnip' + Plug 'hrsh7th/cmp-nvim-lsp' + Plug 'hrsh7th/cmp-nvim-lsp-signature-help' + Plug 'hrsh7th/cmp-buffer' + Plug 'hrsh7th/cmp-path' + Plug 'hrsh7th/cmp-cmdline' " Telescope. Plug 'nvim-lua/plenary.nvim' @@ -62,70 +73,67 @@ endif " LSP & Complete. " ----------------- -"set completeopt=menuone,noinsert,noselect +set completeopt=menuone,noselect lua << EOF + +-- Setup nvim-cmp. +local cmp = require'cmp' + +cmp.setup({ + snippet = { + -- REQUIRED - you must specify a snippet engine + expand = function(args) + vim.fn["vsnip#anonymous"](args.body) + end, + }, + 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 = false }), + }), + sources = cmp.config.sources({ + { name = 'nvim_lsp' }, + { name = 'nvim_lsp_signature_help' }, + }, { + { name = 'vsnip' }, + { name = 'buffer' }, + { name = 'path' } + }) +}) + +-- Setup lspconfig. +local capabilities = require('cmp_nvim_lsp').update_capabilities(vim.lsp.protocol.make_client_capabilities()) +-- Disable LSP snippet completion. +capabilities.textDocument.completion.completionItem.snippetSupport = false +--print(vim.inspect(capabilities)) + local on_attach = function(_client, bufnr) -- Install `omnifunc` completion handler, get completion with . vim.api.nvim_buf_set_option(bufnr, "omnifunc", "v:lua.vim.lsp.omnifunc") - - -- Key mappings. - local opts = { noremap=true, silent=true } - vim.api.nvim_buf_set_keymap(bufnr, "n", "K", "lua vim.lsp.buf.hover()", opts) - vim.api.nvim_buf_set_keymap(bufnr, "n", "", "lua vim.lsp.buf.definition()", opts) - vim.api.nvim_buf_set_keymap(bufnr, "n", "r", "lua vim.lsp.buf.references()", opts) - vim.api.nvim_buf_set_keymap(bufnr, "n", "i", "lua vim.lsp.buf.implementation()", opts) - vim.api.nvim_buf_set_keymap(bufnr, "n", "f", "lua vim.lsp.buf.formatting()", opts) end -- Setup rust-analyzer. require'lspconfig'.rust_analyzer.setup { on_attach = on_attach, + capabilities = capabilities, } -- Setup clangd. require'lspconfig'.clangd.setup { cmd = { "clangd", "--background-index", "--completion-style=detailed" }, on_attach = on_attach, + capabilities = capabilities, } -- Setup pyright. require'lspconfig'.pyright.setup { on_attach = on_attach, + capabilities = capabilities, } --- Setup nvim-compe. -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 = { - path = true; - buffer = false; - calc = false; - nvim_lsp = true; - nvim_lua = false; - vsnip = false; - ultisnips = false; - }; -} - -vim.o.completeopt = "menuone,noselect" - -vim.api.nvim_set_keymap("i", "", "compe#complete()", {expr = true}) -vim.api.nvim_set_keymap("i", "", "compe#confirm('')", {expr = true}) -vim.api.nvim_set_keymap("i", "", "compe#close('')", {expr = true}) - -- Telescope. local picker_cfg = { theme = "ivy" } @@ -146,6 +154,18 @@ EOF vnoremap p "_dP +" LSP +nnoremap lua vim.lsp.buf.definition() +nnoremap lua vim.lsp.buf.type_definition() +nnoremap K lua vim.lsp.buf.hover() +nnoremap lua vim.lsp.buf.signature_help() +inoremap lua vim.lsp.buf.signature_help() +nnoremap r lua vim.lsp.buf.references() +nnoremap i lua vim.lsp.buf.implementation() +nnoremap f lua vim.lsp.buf.formatting() +nnoremap a lua vim.lsp.buf.code_action() +nnoremap n lua vim.lsp.buf.rename() + " Telescope nnoremap fb Telescope buffers nnoremap ff Telescope find_files -- cgit v1.2.3