From 999a1733cf693ab78c26eb1e6a2ab74935762997 Mon Sep 17 00:00:00 2001 From: jdhao Date: Wed, 30 Apr 2025 19:01:57 +0200 Subject: [PATCH] use nvim-cmp for cmd line completion - remove wilder.nvim and its config - add blink.cmp config as backup solution --- README.md | 7 --- lua/config/nvim-cmp.lua | 18 ++++++++ lua/mappings.lua | 2 +- lua/plugin_specs.lua | 96 +++++++++++++++++++++++++++++++++-------- viml_conf/plugins.vim | 46 -------------------- 5 files changed, 98 insertions(+), 71 deletions(-) diff --git a/README.md b/README.md index 3d90501..f46d6e4 100644 --- a/README.md +++ b/README.md @@ -69,7 +69,6 @@ and how to set up on different platforms (Linux, macOS, and Windows). + File tree explorer via [nvim-tree.lua](https://github.com/nvim-tree/nvim-tree.lua). + Better quickfix list with [nvim-bqf](https://github.com/kevinhwang91/nvim-bqf). + Show search index and count with [nvim-hlslens](https://github.com/kevinhwang91/nvim-hlslens). -+ Command line auto-completion via [wilder.nvim](https://github.com/gelguy/wilder.nvim). + User-defined mapping hint via [which-key.nvim](https://github.com/folke/which-key.nvim). + Asynchronous code execution via [asyncrun.vim](https://github.com/skywind3000/asyncrun.vim). + Code highlighting via [nvim-treesitter](https://github.com/nvim-treesitter/nvim-treesitter). @@ -111,12 +110,6 @@ For more UI demos, check [here](https://github.com/jdhao/nvim-config/issues/15).

-## Command-line autocompletion with wilder.nvim - -

- -

- ## Tags

diff --git a/lua/config/nvim-cmp.lua b/lua/config/nvim-cmp.lua index f7f01c4..b5fc78e 100644 --- a/lua/config/nvim-cmp.lua +++ b/lua/config/nvim-cmp.lua @@ -7,6 +7,7 @@ require("cmp_path") require("cmp_buffer") require("cmp_omni") require("cmp_nvim_ultisnips") +require("cmp_cmdline") local MiniIcons = require("mini.icons") @@ -71,6 +72,23 @@ cmp.setup.filetype("tex", { }, }) +cmp.setup.cmdline("/", { + mapping = cmp.mapping.preset.cmdline(), + sources = { + { name = "buffer" }, + }, +}) + +cmp.setup.cmdline(":", { + mapping = cmp.mapping.preset.cmdline(), + sources = cmp.config.sources({ + { name = "path" }, + }, { + { name = "cmdline" }, + }), + matching = { disallow_symbol_nonprefix_matching = false }, +}) + -- see https://github.com/hrsh7th/nvim-cmp/wiki/Menu-Appearance#how-to-add-visual-studio-code-dark-theme-colors-to-the-menu vim.cmd([[ highlight! link CmpItemMenu Comment diff --git a/lua/mappings.lua b/lua/mappings.lua index 9915ef5..f5fb950 100644 --- a/lua/mappings.lua +++ b/lua/mappings.lua @@ -104,7 +104,7 @@ keymap.set("n", "v", "printf('`[%s`]', getregtype()[0])", { }) -- Always use very magic mode for searching -keymap.set("n", "/", [[/\v]]) +-- keymap.set("n", "/", [[/\v]]) -- Search in selected region -- xnoremap / :call feedkeys('/\%>'.(line("'<")-1).'l\%<'.(line("'>")+1)."l") diff --git a/lua/plugin_specs.lua b/lua/plugin_specs.lua index 28c786c..c977f61 100644 --- a/lua/plugin_specs.lua +++ b/lua/plugin_specs.lua @@ -26,15 +26,79 @@ local plugin_specs = { { "hrsh7th/cmp-path", lazy = true }, { "hrsh7th/cmp-buffer", lazy = true }, { "hrsh7th/cmp-omni", lazy = true }, + { "hrsh7th/cmp-cmdline", lazy = true }, { "quangnguyen30192/cmp-nvim-ultisnips", lazy = true }, { "hrsh7th/nvim-cmp", name = "nvim-cmp", - event = "InsertEnter", + event = "VeryLazy", config = function() require("config.nvim-cmp") end, }, + --{ + -- "saghen/blink.cmp", + -- -- optional: provides snippets for the snippet source + -- dependencies = { "rafamadriz/friendly-snippets" }, + + -- -- use a release tag to download pre-built binaries + -- version = "1.*", + + -- ---@module 'blink.cmp' + -- ---@type blink.cmp.Config + -- opts = { + -- -- 'default' (recommended) for mappings similar to built-in completions (C-y to accept) + -- -- 'super-tab' for mappings similar to vscode (tab to accept) + -- -- 'enter' for enter to accept + -- -- 'none' for no mappings + -- -- + -- keymap = { + -- preset = "default", + -- [""] = { "select_next", "fallback" }, + -- [""] = { "select_prev", "fallback" }, + -- [""] = { "select_and_accept", "fallback" }, + -- [""] = { "scroll_documentation_up", "fallback" }, + -- [""] = { "scroll_documentation_down", "fallback" }, + -- }, + + -- appearance = { + -- -- 'mono' (default) for 'Nerd Font Mono' or 'normal' for 'Nerd Font' + -- -- Adjusts spacing to ensure icons are aligned + -- nerd_font_variant = "mono", + -- }, + + -- -- (Default) Only show the documentation popup when manually triggered + -- completion = { + -- documentation = { + -- auto_show = true, + -- }, + -- }, + + -- -- Default list of enabled providers defined so that you can extend it + -- -- elsewhere in your config, without redefining it, due to `opts_extend` + -- sources = { + -- default = { "lsp", "path", "buffer" }, + -- }, + + -- -- (Default) Rust fuzzy matcher for typo resistance and significantly better performance + -- -- You may use a lua implementation instead by using `implementation = "lua"` or fallback to the lua implementation, + -- -- when the Rust fuzzy matcher is not available, by using `implementation = "prefer_rust"` + -- -- + -- -- See the fuzzy documentation for more information + -- fuzzy = { implementation = "prefer_rust_with_warning" }, + -- cmdline = { + -- completion = { + -- menu = { + -- auto_show = true, + -- }, + -- }, + -- keymap = { + -- [""] = { "select_and_accept", "fallback" }, + -- }, + -- }, + -- }, + -- opts_extend = { "sources.default" }, + --}, { "neovim/nvim-lspconfig", event = { "BufRead", "BufNewFile" }, @@ -251,9 +315,13 @@ local plugin_specs = { }, -- Snippet engine and snippet template - { "SirVer/ultisnips", dependencies = { - "honza/vim-snippets", - }, event = "InsertEnter" }, + { + "SirVer/ultisnips", + dependencies = { + "honza/vim-snippets", + }, + event = "InsertEnter", + }, -- Automatic insertion and deletion of a pair of characters { @@ -263,10 +331,13 @@ local plugin_specs = { }, -- Comment plugin - { "tpope/vim-commentary", keys = { - { "gc", mode = "n" }, - { "gc", mode = "v" }, - } }, + { + "tpope/vim-commentary", + keys = { + { "gc", mode = "n" }, + { "gc", mode = "v" }, + }, + }, -- Multiple cursor plugin like Sublime Text? -- 'mg979/vim-visual-multi' @@ -307,9 +378,6 @@ local plugin_specs = { event = { "InsertEnter" }, }, - -- Auto format tools - { "sbdchd/neoformat", cmd = { "Neoformat" } }, - -- Git command inside vim { "tpope/vim-fugitive", @@ -464,12 +532,6 @@ local plugin_specs = { cmd = { "OSCYank", "OSCYankReg" }, }, - -- The missing auto-completion for cmdline! - { - "gelguy/wilder.nvim", - build = ":UpdateRemotePlugins", - }, - -- showing keybindings { "folke/which-key.nvim", diff --git a/viml_conf/plugins.vim b/viml_conf/plugins.vim index 70a7446..2f4bbf8 100644 --- a/viml_conf/plugins.vim +++ b/viml_conf/plugins.vim @@ -240,49 +240,3 @@ endif """"""""""""""""""""""""""""""nvim-gdb settings"""""""""""""""""""""""""""""" nnoremap dp :GdbStartPDB python -m pdb % - -""""""""""""""""""""""""""""""wilder.nvim settings"""""""""""""""""""""""""""""" -call timer_start(250, { -> s:wilder_init() }) - -function! s:wilder_init() abort - try - call wilder#setup({ - \ 'modes': [':', '/', '?'], - \ 'next_key': '', - \ 'previous_key': '', - \ 'accept_key': '', - \ 'reject_key': '' - \ }) - - call wilder#set_option('pipeline', [ - \ wilder#branch( - \ wilder#cmdline_pipeline({ - \ 'language': 'python', - \ 'fuzzy': 1, - \ 'sorter': wilder#python_difflib_sorter(), - \ 'debounce': 30, - \ }), - \ wilder#python_search_pipeline({ - \ 'pattern': wilder#python_fuzzy_pattern(), - \ 'sorter': wilder#python_difflib_sorter(), - \ 'engine': 're', - \ 'debounce': 30, - \ }), - \ ), - \ ]) - - let l:hl = wilder#make_hl('WilderAccent', 'Pmenu', [{}, {}, {'foreground': '#f4468f'}]) - call wilder#set_option('renderer', wilder#popupmenu_renderer({ - \ 'highlighter': wilder#basic_highlighter(), - \ 'max_height': 15, - \ 'highlights': { - \ 'accent': l:hl, - \ }, - \ 'left': [' ', wilder#popupmenu_devicons(),], - \ 'right': [' ', wilder#popupmenu_scrollbar(),], - \ 'apply_incsearch_fix': 0, - \ })) - catch /^Vim\%((\a\+)\)\=:E117/ - echohl Error |echomsg "Wilder.nvim missing"| echohl None - endtry -endfunction