feat(nvim): replace compe with cmp, add tabnine

This commit is contained in:
Oliver Davies 2021-10-06 22:48:17 +01:00
parent d61e4cf210
commit 2d2a2e5490
3 changed files with 40 additions and 62 deletions

View file

@ -86,68 +86,9 @@ key_mapper('n', 'gr', ':lua vim.lsp.buf.references()<CR>')
key_mapper('n', 'gt', ':lua vim.lsp.buf.type_definition()<CR>') key_mapper('n', 'gt', ':lua vim.lsp.buf.type_definition()<CR>')
key_mapper('n', 'gw', ':lua vim.lsp.buf.document_symbol()<CR>') key_mapper('n', 'gw', ':lua vim.lsp.buf.document_symbol()<CR>')
-- Compe vim.opt.termguicolors = true
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 = { vim.cmd [[highlight IndentBlanklineIndent6 guifg=#888888 gui=nocombine]]
path = true;
nvim_lsp = true;
};
}
local t = function(str)
return vim.api.nvim_replace_termcodes(str, true, true, true)
end
local check_back_space = function()
local col = vim.fn.col('.') - 1
if col == 0 or vim.fn.getline('.'):sub(col, col):match('%s') then
return true
else
return false
end
end
-- Use (s-)tab to:
--- move to prev/next item in completion menuone
--- jump to prev/next snippet's placeholder
_G.tab_complete = function()
if vim.fn.pumvisible() == 1 then
return t "<C-n>"
elseif check_back_space() then
return t "<Tab>"
else
return vim.fn['compe#complete']()
end
end
_G.s_tab_complete = function()
if vim.fn.pumvisible() == 1 then
return t "<C-p>"
else
return t "<S-Tab>"
end
end
vim.api.nvim_set_keymap("i", "<Tab>", "v:lua.tab_complete()", {expr = true})
vim.api.nvim_set_keymap("s", "<Tab>", "v:lua.tab_complete()", {expr = true})
vim.api.nvim_set_keymap("i", "<S-Tab>", "v:lua.s_tab_complete()", {expr = true})
vim.api.nvim_set_keymap("s", "<S-Tab>", "v:lua.s_tab_complete()", {expr = true})
--This line is important for auto-import
vim.api.nvim_set_keymap('i', '<cr>', 'compe#confirm("<cr>")', { expr = true })
vim.api.nvim_set_keymap('i', '<c-space>', 'compe#complete()', { expr = true })
vim.opt.list = true vim.opt.list = true
vim.opt.listchars = { vim.opt.listchars = {
@ -155,5 +96,10 @@ vim.opt.listchars = {
} }
require("indent_blankline").setup { require("indent_blankline").setup {
char_highlight_list = {
"IndentBlanklineIndent1",
},
show_end_of_line = true, show_end_of_line = true,
} }
require 'opdavies.plugins.completion'

View file

@ -0,0 +1,28 @@
local cmp = require 'cmp'
cmp.setup {
mapping = {
["<C-d>"] = cmp.mapping.scroll_docs(-4),
["<C-f>"] = cmp.mapping.scroll_docs(4),
["<C-e>"] = cmp.mapping.close(),
["<c-y>"] = cmp.mapping.confirm {
behavior = cmp.ConfirmBehavior.Insert,
select = true,
},
},
sources = {
{ name = 'buffer', priority = 2, keyword_length = 5, max_item_count = 5 },
{ name = 'calc' },
{ name = 'path' },
{ name = 'spell' },
{ name = 'treesitter' },
-- Neovim
{ name = 'nvim_lsp', priority = 10 },
{ name = 'nvim_lua' },
-- Plugins
{ name = 'cmp_tabnine' },
},
}

View file

@ -30,7 +30,11 @@ Plug 'JoosepAlviste/nvim-ts-context-commentstring'
Plug 'nvim-treesitter/nvim-treesitter', {'do': ':TSUpdate'} Plug 'nvim-treesitter/nvim-treesitter', {'do': ':TSUpdate'}
" Completion " Completion
Plug 'hrsh7th/nvim-compe' Plug 'hrsh7th/cmp-buffer'
Plug 'hrsh7th/cmp-nvim-lsp'
Plug 'hrsh7th/cmp-path'
Plug 'hrsh7th/nvim-cmp'
Plug 'tzachar/cmp-tabnine', { 'do': './install.sh' }
" LSP " LSP
Plug 'neovim/nvim-lspconfig' Plug 'neovim/nvim-lspconfig'