-- Setup nvim-cmp. local cmp = require'cmp' cmp.setup({ snippet = { expand = function(args) vim.fn['UltiSnips#Anon'](args.body) -- For `ultisnips` 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.disable, -- Specify `cmp.config.disable` if you want to remove the default `` mapping. [''] = cmp.mapping({ i = cmp.mapping.abort(), c = cmp.mapping.close(), }), -- Accept currently selected item. If none selected, `select` first item. -- Set `select` to `false` to only confirm explicitly selected items. [''] = cmp.mapping.confirm({ select = true }), }, sources = cmp.config.sources({ { name = 'nvim_lsp' }, }, { { name = 'buffer' }, }) }) -- Use buffer source for `/` cmp.setup.cmdline('/', { sources = { { name = 'buffer' } } }) -- Use cmdline & path source for ':' cmp.setup.cmdline(':', { sources = cmp.config.sources({ { name = 'path' } }, { { name = 'cmdline' } }) }) local on_attach = function(client, bufnr) local function buf_set_keymap(...) vim.api.nvim_buf_set_keymap(bufnr, ...) end local opts = { noremap = true, silent = true } buf_set_keymap("n", "gd", "Telescope lsp_definitions", opts) buf_set_keymap("n", "gh", "lua vim.lsp.buf.hover()", opts) buf_set_keymap("n", "gD", "Telescope lsp_implementations", opts) buf_set_keymap("n", "gs", "lua vim.lsp.buf.signature_help()", opts) buf_set_keymap("n", "gR", "lua vim.lsp.buf.rename()", opts) buf_set_keymap("n", "gH", "Telescope lsp_code_actions", opts) buf_set_keymap("n", "gr", "Telescope lsp_references", opts) buf_set_keymap("n", "ge", "lua vim.diagnostic.open_float()", opts) end local lsp_installer = require 'nvim-lsp-installer' lsp_installer.on_server_ready(function(server) local opts = {} opts.on_attach = on_attach opts.capabilities = require('cmp_nvim_lsp').update_capabilities(vim.lsp.protocol.make_client_capabilities()) server:setup(opts) vim.cmd [[ do User LspAttachBuffers ]] end)