diff --git a/completion.lua b/completion.lua new file mode 100644 index 0000000..d5c3351 --- /dev/null +++ b/completion.lua @@ -0,0 +1,52 @@ +-- Completion Plugin Setup +local cmp = require'cmp' +cmp.setup({ + -- Enable LSP snippets + snippet = { + expand = function(args) + vim.fn["vsnip#anonymous"](args.body) + end, + }, + mapping = { + [''] = cmp.mapping.select_prev_item(), + [''] = cmp.mapping.select_next_item(), + -- Add tab support + [''] = cmp.mapping.select_prev_item(), + [''] = cmp.mapping.select_next_item(), + [''] = cmp.mapping.scroll_docs(-4), + [''] = cmp.mapping.scroll_docs(4), + [''] = cmp.mapping.complete(), + [''] = cmp.mapping.close(), + [''] = cmp.mapping.confirm({ + behavior = cmp.ConfirmBehavior.Insert, + select = true, + }) + }, + -- Installed sources: + sources = { + { name = 'path' }, -- file paths + { name = 'nvim_lsp', keyword_length = 3 }, -- from language server + { name = 'nvim_lsp_signature_help'}, -- display function signatures with current parameter emphasized + { name = 'nvim_lua', keyword_length = 2}, -- complete neovim's Lua runtime API such vim.lsp.* + { name = 'buffer', keyword_length = 2 }, -- source current buffer + { name = 'vsnip', keyword_length = 2 }, -- nvim-cmp source for vim-vsnip + { name = 'calc'}, -- source for math calculation + }, + window = { + completion = cmp.config.window.bordered(), + documentation = cmp.config.window.bordered(), + }, + formatting = { + fields = {'menu', 'abbr', 'kind'}, + format = function(entry, item) + local menu_icon ={ + nvim_lsp = 'λ', + vsnip = '⋗', + buffer = 'Ω', + path = '🖫', + } + item.menu = menu_icon[entry.source.name] + return item + end, + }, +}) diff --git a/default.nix b/default.nix index 4808fcb..b3e27b2 100644 --- a/default.nix +++ b/default.nix @@ -42,24 +42,19 @@ in rainbow nvim-web-devicons fzf-vim - coc-sh - coc-nvim - coc-json - coc-yaml - coc-tsserver - coc-prettier - coc-pyright - coc-diagnostic - vimtex - coc-vimtex - coc-html - coc-go - coc-spell-checker editorconfig-nvim # tmuxline-vim nvim-dap nvim-dap-ui nvim-notify + nvim-cmp + cmp-nvim-lsp + cmp-nvim-lua + cmp-buffer + cmp-path + cmp-spell + cmp-conventionalcommits + cmp-calc rust-tools-nvim plenary-nvim crates-nvim diff --git a/init.vim b/init.vim index 5c15a12..a618340 100644 --- a/init.vim +++ b/init.vim @@ -5,45 +5,6 @@ set hidden " disable mouse set mouse= -" GoTo code navigation. -nmap gd (coc-definition) -nmap gy (coc-type-definition) -nmap gi (coc-implementation) -nmap gr (coc-references) - - -" Rename -nmap rn (coc-rename) - -" Use K to show documentation in preview window. -nnoremap K :call ShowDocumentation() - -nmap ac (coc-codeaction) -nmap as (coc-codeaction-cursor) -nmap cl (coc-codelens-action) - -nmap [G (coc-diagnostic-next-error) -nmap ]G (coc-diagnostic-prev-error) - -nmap [g (coc-diagnostic-next) -nmap ]g (coc-diagnostic-prev) - -function! ShowDocumentation() - if CocAction('hasProvider', 'hover') - call CocActionAsync('doHover') - else - call feedkeys('K', 'in') - endif -endfunction - -" Highlight the symbol and its references when holding the cursor. -autocmd CursorHold * silent call CocActionAsync('highlight') - -" Formatting selected code. -xmap f (coc-format-selected) -nmap f (coc-format-selected) -nmap F (coc-format) - " " Copy to clipboard vnoremap y "+y @@ -67,9 +28,6 @@ map to :tabonly " Display line numbers set number relativenumber -inoremap coc#pum#visible() ? coc#_select_confirm() - \: "\u\\=coc#on_enter()\" - map :mksession! .nvim_session " Quick write session with F3 map :source .nvim_session " And load session with F4