From 95db4c2bd974fed1fe26864d9d6cda482aaff2e8 Mon Sep 17 00:00:00 2001 From: Fredrik Ekre Date: Sat, 26 Mar 2022 23:55:26 +0100 Subject: [PATCH] [nvim] Initial nvim-cmp configuration. --- .config/nvim/init.vim | 35 +++++++++++++++++++++++++++++++++++ .vimrc | 10 ++++++++++ 2 files changed, 45 insertions(+) diff --git a/.config/nvim/init.vim b/.config/nvim/init.vim index 0720468..8d3da5e 100644 --- a/.config/nvim/init.vim +++ b/.config/nvim/init.vim @@ -4,6 +4,40 @@ source ~/.vimrc lua << EOF +-- Setup nvim-cmp. +vim.opt.completeopt = {"menu", "menuone", "noselect"} + +local cmp = require'cmp' + +cmp.setup({ + snippet = { + expand = function(args) + require('luasnip').lsp_expand(args.body) -- For `luasnip` users. + end, + }, + mapping = { + -- [''] = cmp.mapping(cmp.mapping.scroll_docs(-4), { 'i', 'c' }), + -- [''] = cmp.mapping(cmp.mapping.scroll_docs(4), { 'i', 'c' }), + [''] = cmp.mapping(cmp.mapping.complete(), { 'i', 'c' }), + -- [''] = cmp.config.enable, -- Specify `cmp.config.disable` if you want to remove the default `` mapping. + -- [''] = cmp.mapping({ + -- i = cmp.mapping.abort(), + -- c = cmp.mapping.close(), + -- }), + [''] = 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 = 'luasnip' }, -- For luasnip users. + }, + { + { name = 'buffer' }, + }) +}) + +-- Setup lspconfig: capabilities is passed to lspconfig.$server.setup +local capabilities = require('cmp_nvim_lsp').update_capabilities(vim.lsp.protocol.make_client_capabilities()) + -- Set LSP keymappings in on_attach (i.e. only in buffers with LSP active) local on_attach = function(client, bufnr) opts = { noremap=true, silent=true } @@ -25,6 +59,7 @@ require'lspconfig'.julials.setup({ util.path.dirname(fname) end, on_attach = on_attach, + capabilities = capabilities, }) EOF diff --git a/.vimrc b/.vimrc index 8ac6c0d..0868a13 100644 --- a/.vimrc +++ b/.vimrc @@ -21,7 +21,17 @@ call plug#begin('~/.vim/plugged') Plug 'tpope/vim-fugitive' if has('nvim') + " LSP helpers Plug 'neovim/nvim-lspconfig' + " nvim-cmp and completion sources + Plug 'hrsh7th/cmp-nvim-lsp' + Plug 'hrsh7th/cmp-buffer' + Plug 'hrsh7th/cmp-path' + " Plug 'hrsh7th/cmp-cmdline' + Plug 'hrsh7th/nvim-cmp' + " Snippet engine required for nvim-cmp (expands things from LS) + Plug 'L3MON4D3/LuaSnip' + Plug 'saadparwaiz1/cmp_luasnip' end call plug#end()