diff --git a/.vimrc b/.vimrc index 72d4345..eb4f8eb 100644 --- a/.vimrc +++ b/.vimrc @@ -46,11 +46,8 @@ set ruler " I hate split above, so make it split below. Likewise, to the right. set splitbelow -" For autocomplete, show a menu, show it when there's only one option, -" and only complete the longest common bit instead of the whole thing (like -" bash). -"set completeopt=menu,menuone,longest -set completeopt=noinsert,menuone,noselect,longest +" For autocomplete, follow requirements for nvim-compe +set completeopt=menuone,noselect set signcolumn=yes set shortmess+=c @@ -149,7 +146,7 @@ Plug 'tpope/vim-abolish' Plug 'sheerun/vim-polyglot' Plug 'Shougo/denite.nvim' Plug 'plytophogy/vim-virtualenv' -Plug 'ervandew/supertab' +"Plug 'ervandew/supertab' "Plug 'ncm2/ncm2' "Plug 'roxma/nvim-yarp' @@ -200,7 +197,8 @@ Plug 'zchee/vim-goasm' "Plug 'neoclide/coc.nvim', {'branch': 'release'} Plug 'neovim/nvim-lspconfig' Plug 'nvim-lua/lsp_extensions.nvim' -Plug 'nvim-lua/completion-nvim' +Plug 'hrsh7th/nvim-compe' +"Plug 'nvim-lua/completion-nvim' Plug 'onsails/lspkind-nvim' " Plugins that do specific things @@ -273,7 +271,6 @@ local nvim_lsp = require'lspconfig' -- function to attach completion when setting up lsp local on_attach = function(client) - require'completion'.on_attach(client) end -- Enable rust_analyzer @@ -289,6 +286,65 @@ vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with( } ) +-- Compe setup +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 = { + 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}) + require('lspkind').init({ -- disables text annotations with_text = false, @@ -322,16 +378,8 @@ require('lspkind').init({ Struct = 'struct', }, }) - EOF -" Use and to navigate through popup menu -inoremap pumvisible() ? "\" : "\" -inoremap pumvisible() ? "\" : "\" - -" use as trigger keys -imap (completion_smart_tab) -imap (completion_smart_s_tab) " Code navigation shortcuts nnoremap gd lua vim.lsp.buf.definition() @@ -360,6 +408,11 @@ let g:completion_matching_strategy_list = ['exact', 'substring', 'fuzzy'] let g:completion_matching_smart_case = 1 let g:completion_sorting = 'length' +inoremap compe#confirm('') +inoremap compe#close('') +inoremap compe#scroll({ 'delta': +4 }) +inoremap compe#scroll({ 'delta': -4 }) + " **** End LSP