Browse Source

[nvim] Initial nvim-cmp configuration.

master
Fredrik Ekre 4 years ago
parent
commit
95db4c2bd9
  1. 35
      .config/nvim/init.vim
  2. 10
      .vimrc

35
.config/nvim/init.vim

@ -4,6 +4,40 @@ source ~/.vimrc @@ -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 = {
-- ['<C-b>'] = cmp.mapping(cmp.mapping.scroll_docs(-4), { 'i', 'c' }),
-- ['<C-f>'] = cmp.mapping(cmp.mapping.scroll_docs(4), { 'i', 'c' }),
['<C-Space>'] = cmp.mapping(cmp.mapping.complete(), { 'i', 'c' }),
-- ['<C-y>'] = cmp.config.enable, -- Specify `cmp.config.disable` if you want to remove the default `<C-y>` mapping.
-- ['<C-e>'] = cmp.mapping({
-- i = cmp.mapping.abort(),
-- c = cmp.mapping.close(),
-- }),
['<CR>'] = 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({ @@ -25,6 +59,7 @@ require'lspconfig'.julials.setup({
util.path.dirname(fname)
end,
on_attach = on_attach,
capabilities = capabilities,
})
EOF

10
.vimrc

@ -21,7 +21,17 @@ call plug#begin('~/.vim/plugged') @@ -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()

Loading…
Cancel
Save