From 3249d3ddf11723a5846f37acbe948fe7d888a3cd Mon Sep 17 00:00:00 2001 From: Kevin MacMartin Date: Mon, 4 Mar 2024 14:39:06 -0500 Subject: [PATCH] Replace deoplete with nvim-cmp and a collection of autocompletion sources, and refactor a bunch of the config --- .gitmodules | 30 +++++++++++--- init.vim | 57 ++++++++++---------------- readme.md | 19 +++++---- update | 26 +++++++++++- vim/bundle/cmp-buffer | 1 + vim/bundle/cmp-nvim-tags | 1 + vim/bundle/cmp-omni | 1 + vim/bundle/cmp-snippy | 1 + vim/bundle/cmp-treesitter | 1 + vim/bundle/deoplete.nvim | 1 - vim/bundle/neco-syntax | 1 - vim/bundle/nvim-cmp | 1 + vim/bundle/nvim-snippy | 1 + vim/bundle/vim-polyglot-darkcloud | 2 +- vim/bundle/vim-snippets | 1 + vim/config/plugins/ale.vim | 4 +- vim/config/plugins/deoplete.vim | 8 ---- vim/config/plugins/nvim-cmp.lua | 55 +++++++++++++++++++++++++ vim/config/plugins/nvim-treesitter.lua | 44 ++++++++++---------- vim/config/plugins/tagbar.vim | 8 +--- vim/config/plugins/vim-gutentags.vim | 14 +++++-- 21 files changed, 180 insertions(+), 97 deletions(-) create mode 160000 vim/bundle/cmp-buffer create mode 160000 vim/bundle/cmp-nvim-tags create mode 160000 vim/bundle/cmp-omni create mode 160000 vim/bundle/cmp-snippy create mode 160000 vim/bundle/cmp-treesitter delete mode 160000 vim/bundle/deoplete.nvim delete mode 160000 vim/bundle/neco-syntax create mode 160000 vim/bundle/nvim-cmp create mode 160000 vim/bundle/nvim-snippy create mode 160000 vim/bundle/vim-snippets delete mode 100644 vim/config/plugins/deoplete.vim create mode 100644 vim/config/plugins/nvim-cmp.lua diff --git a/.gitmodules b/.gitmodules index 0ea8f8f..88a7311 100644 --- a/.gitmodules +++ b/.gitmodules @@ -52,12 +52,6 @@ [submodule "vim/bundle/lightline-ale"] path = vim/bundle/lightline-ale url = https://github.com/maximbaz/lightline-ale -[submodule "vim/bundle/deoplete.nvim"] - path = vim/bundle/deoplete.nvim - url = https://github.com/Shougo/deoplete.nvim -[submodule "vim/bundle/neco-syntax"] - path = vim/bundle/neco-syntax - url = https://github.com/Shougo/neco-syntax.git [submodule "vim/bundle/vim-gutentags"] path = vim/bundle/vim-gutentags url = https://github.com/ludovicchabant/vim-gutentags.git @@ -70,3 +64,27 @@ [submodule "vim/bundle/nvim-treesitter"] path = vim/bundle/nvim-treesitter url = https://github.com/nvim-treesitter/nvim-treesitter +[submodule "vim/bundle/nvim-cmp"] + path = vim/bundle/nvim-cmp + url = https://github.com/hrsh7th/nvim-cmp +[submodule "vim/bundle/nvim-snippy"] + path = vim/bundle/nvim-snippy + url = https://github.com/dcampos/nvim-snippy +[submodule "vim/bundle/vim-snippets"] + path = vim/bundle/vim-snippets + url = https://github.com/honza/vim-snippets +[submodule "vim/bundle/cmp-treesitter"] + path = vim/bundle/cmp-treesitter + url = https://github.com/ray-x/cmp-treesitter +[submodule "vim/bundle/cmp-nvim-tags"] + path = vim/bundle/cmp-nvim-tags + url = https://github.com/quangnguyen30192/cmp-nvim-tags +[submodule "vim/bundle/cmp-snippy"] + path = vim/bundle/cmp-snippy + url = https://github.com/dcampos/cmp-snippy +[submodule "vim/bundle/cmp-buffer"] + path = vim/bundle/cmp-buffer + url = https://github.com/hrsh7th/cmp-buffer +[submodule "vim/bundle/cmp-omni"] + path = vim/bundle/cmp-omni + url = https://github.com/hrsh7th/cmp-omni diff --git a/init.vim b/init.vim index bd79692..cd64f2f 100644 --- a/init.vim +++ b/init.vim @@ -32,7 +32,15 @@ if &term != "linux" endif "load user config: -runtime local/user.vim +runtime user.vim + +"set default values for user settings +let g:autostartchecker = get(g:, "autostartchecker", 0) +let g:autostarttagbar = get(g:, "autostarttagbar", 0) +let g:enabletreesitter = get(g:, "enabletreesitter", 0) +let g:enablecompletion = get(g:, "enablecompletion", 0) +let g:enableautotags = get(g:, "enableautotags", 0) +let g:enablepowerline = get(g:, "enablepowerline", 0) "load settings: runtime config/settings.vim @@ -40,44 +48,21 @@ runtime config/settings.vim "initialize plugins: let g:pathogen_disabled = get(g:, "pathogen_disabled", []) -if has('python3') - "check for python-neovim - redir => python_neovim_check - silent python3 exec("import pkgutil\nneovim = pkgutil.find_loader('neovim')\nfound = neovim is not None\nprint(found)") - redir END - - if substitute(python_neovim_check, '^\n*\([^\n]*\)\n*$', '\1', '') == 'True' - let g:python_neovim = 1 - else - let g:python_neovim = 0 - endif - - "check for python-msgpack - redir => python_msgpack_check - silent python3 exec("import pkgutil\nmsgpack = pkgutil.find_loader('msgpack')\nfound = msgpack is not None\nprint(found)") - redir END - - if substitute(python_msgpack_check, '^\n*\([^\n]*\)\n*$', '\1', '') == 'True' - let g:python_msgpack = 1 - else - let g:python_msgpack = 0 - endif -else - "if python isn't available disable plugins that depend on it and set library variables to false - call add(g:pathogen_disabled, 'MatchTagAlways') - let g:python_neovim = 0 - let g:python_msgpack = 0 -endif - -"don't load vim-gutentags if ctags can't be found -if !executable('ctags') +"don't load vim-gutentags if g:enableautotags is false or ctags isn't in path +if !g:enableautotags || !executable('ctags') call add(g:pathogen_disabled, 'vim-gutentags') endif -if !g:python_neovim || !g:python_msgpack - "don't load deoplete if either of its python dependencies are missing - call add(g:pathogen_disabled, 'deoplete.nvim') - call add(g:pathogen_disabled, 'neco-syntax') +"don't load nvim-cmp or its dependencies if g:enablecompletion is false +if !g:enablecompletion + call add(g:pathogen_disabled, 'nvim-cmp') + call add(g:pathogen_disabled, 'cmp-buffer') + call add(g:pathogen_disabled, 'cmp-nvim-tags') + call add(g:pathogen_disabled, 'cmp-omni') + call add(g:pathogen_disabled, 'cmp-snippy') + call add(g:pathogen_disabled, 'cmp-treesitter') + call add(g:pathogen_disabled, 'nvim-snippy') + call add(g:pathogen_disabled, 'vim-snippets') endif "use pathogen to load plugins that haven't been disabled diff --git a/readme.md b/readme.md index ce40c01..323b12b 100644 --- a/readme.md +++ b/readme.md @@ -11,12 +11,9 @@ A theme, config and collection of plugins for Neovim ## Optional Requirements -* **Compilers, Linters and Runtimes**: The ale plugin can use compilers, linters and runtimes to provide real-time syntax checking -* **CTags**: Required by _tagbar_ and optional for _coc.nvim_ ([ctags website](http://ctags.sourceforge.net)) -* **Powerline Fonts**: Required to enable the fancier looking status line ([powerline-fonts repo](https://github.com/Lokaltog/powerline-fonts)) -* **Python**: Required for _deoplete_ autocompletion functionality -* **Neovim Python Module**: Required for _deoplete_ autocompletion -* **Python Msgpack**: Required for _deoplete_ autocompletion +* **Powerline Fonts**: Required to enable the fancier looking status line +* **Universal CTags**: Required by _vim-gutentags_, _tagbar_ and optional for _nvim-cmp_ +* **Compilers, Linters and Runtimes**: The _ale_ plugin can use compilers, linters and runtimes to provide real-time syntax checking ## Distribution Features @@ -120,11 +117,17 @@ For a complete list of mappings specific to **darkcloud-nvimconfig**, check the * [ale](https://github.com/w0rp/ale): Asynchronous Lint Engine * [Comment.nvim](https://github.com/numToStr/Comment.nvim): Smart and Powerful commenting plugin for neovim * [nvim-ts-context-commentstring](https://github.com/JoosepAlviste/nvim-ts-context-commentstring): A Neovim plugin for setting the commentstring option based on the cursor location in the file. The location is checked via treesitter queries -* [deoplete.nvim](https://github.com/Shougo/deoplete.nvim): Dark powered asynchronous completion framework for neovim/Vim8 - * [neco-syntax](https://github.com/Shougo/neco-syntax): Syntax source for neocomplete/deoplete/ncm * [editorconfig-vim](https://github.com/editorconfig/editorconfig-vim): EditorConfig plugin for Vim that auto-configures certain settings when a .editorconfig file is present * [lightline.vim](https://github.com/itchyny/lightline.vim): A light and configurable statusline/tabline for Vim * [lightline-ale](https://github.com/maximbaz/lightline-ale): Provides ALE indicator for the lightline vim plugin +* [nvim-cmp](https://github.com/hrsh7th/nvim-cmp): A completion engine plugin for neovim written in Lua + * [cmp-buffer](https://github.com/hrsh7th/cmp-buffer): Buffer words source for nvim-cmp + * [cmp-nvim-tags](https://github.com/quangnguyen30192/cmp-nvim-tags): Tags source for nvim-cmp + * [cmp-omni](https://github.com/hrsh7th/cmp-omni): Omnifunc source for cmp-nvim + * [cmp-snippy](https://github.com/dcampos/cmp-snippy): Nvim-snippy completion source for nvim-cmp + * [cmp-treesitter](https://github.com/ray-x/cmp-treesitter): Treesitter source for nvim-cmp + * [nvim-snippy](https://github.com/dcampos/nvim-snippy): Snippet plugin for Neovim written in Lua + * [vim-snippets](https://github.com/honza/vim-snippets): Snippets files for various programming languages * [nvim-treesitter](https://github.com/nvim-treesitter/nvim-treesitter): Treesitter configurations and abstraction layer for Neovim * [ReplaceWithRegister](https://github.com/vim-scripts/ReplaceWithRegister): Replace text with the contents of a register (for paste+replace without writing over the buffer) * [splitjoin.vim](https://github.com/AndrewRadev/splitjoin.vim): Simplifies the transition between multiline and single-line code diff --git a/update b/update index b223677..dd14b44 100755 --- a/update +++ b/update @@ -17,7 +17,7 @@ local_bundle_dir=local/bundle error_log=update-errors.log script_name="${0//*\/}" -script_home="${0%$script_name}" +script_home="${0%"$script_name"}" if [[ -z "$script_home" ]]; then script_home="$PWD" @@ -70,6 +70,16 @@ function show_help { printf '%s\n' 'Run with no arguments to update darkcloud-nvimconfig' } +# update coq_nvim dependencies +function update_coq_dependencies { + coq_nvim_bundle=vim/bundle/coq_nvim + [[ -d "$coq_nvim_bundle" ]] || return 1 + pushd "$coq_nvim_bundle" >/dev/null || return 1 + python3 -m coq deps >/dev/null 2>&1 || error 'python3 -m coq deps' 'Updating COQ dependencies failed' + popd >/dev/null || return 1 + return 0 +} + # # SETUP # @@ -301,6 +311,20 @@ else error "nvim -c ':UpdateRemotePlugins|qa!'" 'Updating remote plugins for neovim failed' fi +# +# INSTALL/UPDATE COQ DEPENDENCIES +# + +printf '%s' "$cbg_blue >> Updating coq_nvim dependencies:$c_reset" +update_coq_dependencies + +if (( ! $? )); then + printf '%s\n' "$cfg_green_bold SUCCESS! $c_reset" +else + printf '%s\n' "$cfg_red_bold FAIL! $c_reset" + error 'python3 -m coq deps' 'Updating coq_nvim dependencies failed' +fi + # # FINISH # diff --git a/vim/bundle/cmp-buffer b/vim/bundle/cmp-buffer new file mode 160000 index 0000000..3022dbc --- /dev/null +++ b/vim/bundle/cmp-buffer @@ -0,0 +1 @@ +Subproject commit 3022dbc9166796b644a841a02de8dd1cc1d311fa diff --git a/vim/bundle/cmp-nvim-tags b/vim/bundle/cmp-nvim-tags new file mode 160000 index 0000000..30bdc2e --- /dev/null +++ b/vim/bundle/cmp-nvim-tags @@ -0,0 +1 @@ +Subproject commit 30bdc2eec86eb66730af541bb06d24d4a67e3eeb diff --git a/vim/bundle/cmp-omni b/vim/bundle/cmp-omni new file mode 160000 index 0000000..4ef610b --- /dev/null +++ b/vim/bundle/cmp-omni @@ -0,0 +1 @@ +Subproject commit 4ef610bbd85a5ee4e97e09450c0daecbdc60de86 diff --git a/vim/bundle/cmp-snippy b/vim/bundle/cmp-snippy new file mode 160000 index 0000000..6e39210 --- /dev/null +++ b/vim/bundle/cmp-snippy @@ -0,0 +1 @@ +Subproject commit 6e39210aa3a74e2bf6462f492eaf0d436cd2b7d3 diff --git a/vim/bundle/cmp-treesitter b/vim/bundle/cmp-treesitter new file mode 160000 index 0000000..13e4ef8 --- /dev/null +++ b/vim/bundle/cmp-treesitter @@ -0,0 +1 @@ +Subproject commit 13e4ef8f4dd5639fca2eb9150e68f47639a9b37d diff --git a/vim/bundle/deoplete.nvim b/vim/bundle/deoplete.nvim deleted file mode 160000 index 00a1799..0000000 --- a/vim/bundle/deoplete.nvim +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 00a179968eb5f53408dafc22567c1e2933c01079 diff --git a/vim/bundle/neco-syntax b/vim/bundle/neco-syntax deleted file mode 160000 index f8d7b74..0000000 --- a/vim/bundle/neco-syntax +++ /dev/null @@ -1 +0,0 @@ -Subproject commit f8d7b748b022aac8ce73458574da5616f1c5fb65 diff --git a/vim/bundle/nvim-cmp b/vim/bundle/nvim-cmp new file mode 160000 index 0000000..04e0ca3 --- /dev/null +++ b/vim/bundle/nvim-cmp @@ -0,0 +1 @@ +Subproject commit 04e0ca376d6abdbfc8b52180f8ea236cbfddf782 diff --git a/vim/bundle/nvim-snippy b/vim/bundle/nvim-snippy new file mode 160000 index 0000000..6295b6c --- /dev/null +++ b/vim/bundle/nvim-snippy @@ -0,0 +1 @@ +Subproject commit 6295b6cb30725c343a8986096c9f04b0e7646c52 diff --git a/vim/bundle/vim-polyglot-darkcloud b/vim/bundle/vim-polyglot-darkcloud index a07a3e8..25afe7e 160000 --- a/vim/bundle/vim-polyglot-darkcloud +++ b/vim/bundle/vim-polyglot-darkcloud @@ -1 +1 @@ -Subproject commit a07a3e86ea173dd71525ee8a6fb0fcc58122cd87 +Subproject commit 25afe7ebbc7c34f711685f5d29308a82ed5350ac diff --git a/vim/bundle/vim-snippets b/vim/bundle/vim-snippets new file mode 160000 index 0000000..393d980 --- /dev/null +++ b/vim/bundle/vim-snippets @@ -0,0 +1 @@ +Subproject commit 393d980157b8149b3ff65a48bc4aae24dca9c846 diff --git a/vim/config/plugins/ale.vim b/vim/config/plugins/ale.vim index c6dd599..01ffe04 100644 --- a/vim/config/plugins/ale.vim +++ b/vim/config/plugins/ale.vim @@ -1,5 +1,5 @@ -"autostart syntax checking when vim opens to a compatible filetype (default: 0) -if !exists("g:autostartchecker") || &diff +"always disable ale in diff mode +if &diff let g:autostartchecker = 0 endif diff --git a/vim/config/plugins/deoplete.vim b/vim/config/plugins/deoplete.vim deleted file mode 100644 index fb59e9e..0000000 --- a/vim/config/plugins/deoplete.vim +++ /dev/null @@ -1,8 +0,0 @@ -"enable completion (default: 0) -if !exists("g:enablecompletion") - let g:enablecompletion = 0 -endif - -if !g:enablecompletion && g:python_neovim - let g:deoplete#enable_at_startup = 1 -endif diff --git a/vim/config/plugins/nvim-cmp.lua b/vim/config/plugins/nvim-cmp.lua new file mode 100644 index 0000000..7c97b52 --- /dev/null +++ b/vim/config/plugins/nvim-cmp.lua @@ -0,0 +1,55 @@ +if (vim.g.enablecompletion == 1) then + local snippy = require("snippy") + local cmp = require"cmp" + + local has_words_before = function() + unpack = unpack or table.unpack + local line, col = unpack(vim.api.nvim_win_get_cursor(0)) + return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil + end + + cmp.setup({ + snippet = { + expand = function(args) + require "snippy".expand_snippet(args.body) + end + }, + window = { + completion = cmp.config.window.bordered(), + documentation = cmp.config.window.bordered(), + }, + mapping = cmp.mapping.preset.insert({ + [""] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_next_item() + elseif snippy.can_expand_or_advance() then + snippy.expand_or_advance() + elseif has_words_before() then + cmp.complete() + else + fallback() + end + end, { "i", "s" }), + + [""] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_prev_item() + elseif snippy.can_jump(-1) then + snippy.previous() + else + fallback() + end + end, { "i", "s" }), + + [""] = cmp.mapping.abort(), + [""] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items. + }), + sources = cmp.config.sources({ + { name = "buffer" }, + { name = "treesitter" }, + { name = "omni" }, + { name = "tags", option = { current_buffer_only = true } }, + { name = "snippy" }, + }) + }) +end diff --git a/vim/config/plugins/nvim-treesitter.lua b/vim/config/plugins/nvim-treesitter.lua index 942a08b..5eb5951 100644 --- a/vim/config/plugins/nvim-treesitter.lua +++ b/vim/config/plugins/nvim-treesitter.lua @@ -1,26 +1,24 @@ -if (vim.g.enabletreesitter ~= nill) then - if (vim.g.enabletreesitter == 1) then - local parser_dir +if (vim.g.enabletreesitter == 1) then + local parser_dir - if (vim.g.treesitterparserdir == nill) then - parser_dir = "~/.config/nvim/treesitter-parsers" - else - parser_dir = vim.g.treesitterparserdir - end - - vim.opt.runtimepath:append(parser_dir) - - require'nvim-treesitter.configs'.setup { - ensure_installed = { "bash", "c", "cpp", "git_config", "html", "java", "javascript", "json", "lua", "php", "python", "query", "rust", "toml", "typescript", "vim", "vue" }, - sync_install = false, - auto_install = false, - parser_install_dir = parser_dir, - - highlight = { - enable = true, - disable = {}, - additional_vim_regex_highlighting = false, - } - } + if (vim.g.treesitterparserdir == nill) then + parser_dir = "~/.config/nvim/treesitter-parsers" + else + parser_dir = vim.g.treesitterparserdir end + + vim.opt.runtimepath:append(parser_dir) + + require'nvim-treesitter.configs'.setup { + ensure_installed = { "bash", "c", "cpp", "git_config", "html", "java", "javascript", "json", "lua", "php", "python", "query", "rust", "toml", "typescript", "vim", "vue" }, + sync_install = false, + auto_install = false, + parser_install_dir = parser_dir, + + highlight = { + enable = true, + disable = {}, + additional_vim_regex_highlighting = false, + } + } end diff --git a/vim/config/plugins/tagbar.vim b/vim/config/plugins/tagbar.vim index 802b279..16c3075 100644 --- a/vim/config/plugins/tagbar.vim +++ b/vim/config/plugins/tagbar.vim @@ -1,9 +1,5 @@ -"autostart tagbar when vim opens to a compatible filetype (default: 0) -if !exists("g:autostarttagbar") - let g:autostarttagbar = 0 -endif - -if !&diff && (g:autostarttagbar == 1) +"start the tagbar if g:autostarttagbar is true while not in diff mode +if g:autostarttagbar == 1 && !&diff autocmd VimEnter * nested :call tagbar#autoopen(1) endif diff --git a/vim/config/plugins/vim-gutentags.vim b/vim/config/plugins/vim-gutentags.vim index fc7d47f..9d3b0f0 100644 --- a/vim/config/plugins/vim-gutentags.vim +++ b/vim/config/plugins/vim-gutentags.vim @@ -1,12 +1,18 @@ let g:gutentags_cache_dir = get(g:, "gutentags_cache_dir", "~/.config/nvim/gutentags") +let g:gutentags_ctags_exclude = [ + \ '*.json', + \ '*.lock', + \ '*.min.*', + \ 'node_modules/*', + \ 'vendor/*', +\ ] + let g:gutentags_file_list_command = { \ 'markers': { - \ '.git': 'git ls-files', + \ '.git': 'git ls-files', \ }, \ } "prevent automatically generating the tagfile and syntax highlighting tags (default: 0) -if !exists("g:enableautotags") || g:enableautotags == 0 - let g:gutentags_enabled = 0 -endif +let g:gutentags_enabled = g:enableautotags