From 2d2a2e5490b402716ab8746478458ddaa2b74921 Mon Sep 17 00:00:00 2001 From: Oliver Davies Date: Wed, 6 Oct 2021 22:48:17 +0100 Subject: [PATCH] feat(nvim): replace compe with cmp, add tabnine --- nvim/.config/nvim/lua/opdavies/init.lua | 68 ++----------------- .../nvim/lua/opdavies/plugins/completion.lua | 28 ++++++++ nvim/.config/nvim/plugins.vim | 6 +- 3 files changed, 40 insertions(+), 62 deletions(-) create mode 100644 nvim/.config/nvim/lua/opdavies/plugins/completion.lua diff --git a/nvim/.config/nvim/lua/opdavies/init.lua b/nvim/.config/nvim/lua/opdavies/init.lua index a37e3e9..896c9e0 100644 --- a/nvim/.config/nvim/lua/opdavies/init.lua +++ b/nvim/.config/nvim/lua/opdavies/init.lua @@ -86,68 +86,9 @@ key_mapper('n', 'gr', ':lua vim.lsp.buf.references()') key_mapper('n', 'gt', ':lua vim.lsp.buf.type_definition()') key_mapper('n', 'gw', ':lua vim.lsp.buf.document_symbol()') --- 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; +vim.opt.termguicolors = true - source = { - 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 "" - elseif check_back_space() then - return t "" - else - return vim.fn['compe#complete']() - end -end -_G.s_tab_complete = function() - if vim.fn.pumvisible() == 1 then - return t "" - else - return t "" - end -end - -vim.api.nvim_set_keymap("i", "", "v:lua.tab_complete()", {expr = true}) -vim.api.nvim_set_keymap("s", "", "v:lua.tab_complete()", {expr = true}) -vim.api.nvim_set_keymap("i", "", "v:lua.s_tab_complete()", {expr = true}) -vim.api.nvim_set_keymap("s", "", "v:lua.s_tab_complete()", {expr = true}) - ---This line is important for auto-import -vim.api.nvim_set_keymap('i', '', 'compe#confirm("")', { expr = true }) -vim.api.nvim_set_keymap('i', '', 'compe#complete()', { expr = true }) +vim.cmd [[highlight IndentBlanklineIndent6 guifg=#888888 gui=nocombine]] vim.opt.list = true vim.opt.listchars = { @@ -155,5 +96,10 @@ vim.opt.listchars = { } require("indent_blankline").setup { + char_highlight_list = { + "IndentBlanklineIndent1", + }, show_end_of_line = true, } + +require 'opdavies.plugins.completion' diff --git a/nvim/.config/nvim/lua/opdavies/plugins/completion.lua b/nvim/.config/nvim/lua/opdavies/plugins/completion.lua new file mode 100644 index 0000000..8d4c249 --- /dev/null +++ b/nvim/.config/nvim/lua/opdavies/plugins/completion.lua @@ -0,0 +1,28 @@ +local cmp = require 'cmp' + +cmp.setup { + mapping = { + [""] = cmp.mapping.scroll_docs(-4), + [""] = cmp.mapping.scroll_docs(4), + [""] = cmp.mapping.close(), + [""] = 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' }, + }, +} diff --git a/nvim/.config/nvim/plugins.vim b/nvim/.config/nvim/plugins.vim index 3f91bec..abb2c0a 100644 --- a/nvim/.config/nvim/plugins.vim +++ b/nvim/.config/nvim/plugins.vim @@ -30,7 +30,11 @@ Plug 'JoosepAlviste/nvim-ts-context-commentstring' Plug 'nvim-treesitter/nvim-treesitter', {'do': ':TSUpdate'} " 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 Plug 'neovim/nvim-lspconfig'