From 99d688e6459c7963b00a95d544de7a3de951a70b Mon Sep 17 00:00:00 2001 From: Tomas Slusny Date: Mon, 3 Mar 2025 17:51:42 +0100 Subject: vim-patch:9.1.1166: command-line auto-completion hard with wildmenu Problem: command-line auto-completion hard with wildmenu Solution: implement "noselect" wildoption value (Girish Palya) When `noselect` is present in `wildmode` and 'wildmenu' is enabled, the completion menu appears without pre-selecting the first item. This change makes it easier to implement command-line auto-completion, where the menu dynamically appears as characters are typed, and `` can be used to manually select an item. This can be achieved by leveraging the `CmdlineChanged` event to insert `wildchar(m)`, triggering completion menu. Without this change, auto-completion using the 'wildmenu' mechanism is not feasible, as it automatically inserts the first match, preventing dynamic selection. The following Vimscript snippet demonstrates how to configure auto-completion using `noselect`: ```vim vim9script set wim=noselect:lastused,full wop=pum wcm= wmnu autocmd CmdlineChanged : timer_start(0, function(CmdComplete, [getcmdline()])) def CmdComplete(cur_cmdline: string, timer: number) var [cmdline, curpos] = [getcmdline(), getcmdpos()] if cur_cmdline ==# cmdline # Avoid completing each character in keymaps and pasted text && !pumvisible() && curpos == cmdline->len() + 1 if cmdline[curpos - 2] =~ '[\w*/:]' # Reduce noise by completing only selected characters feedkeys("\", "ti") set eventignore+=CmdlineChanged # Suppress redundant completion attempts timer_start(0, (_) => { getcmdline()->substitute('\%x00$', '', '')->setcmdline() # Remove if no completion items exist set eventignore-=CmdlineChanged }) endif endif enddef ``` fixes: vim/vim#16551 closes: vim/vim#16759 https://github.com/vim/vim/commit/2bacc3e5fb3569e0fd98e129cb1e422ca18b80a6 Cherry-pick Wildmode_Tests() change from patch 9.0.0418. Co-authored-by: Girish Palya Signed-off-by: Tomas Slusny --- src/nvim/options.lua | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'src/nvim/options.lua') diff --git a/src/nvim/options.lua b/src/nvim/options.lua index d1d5a56082..2516d1a970 100644 --- a/src/nvim/options.lua +++ b/src/nvim/options.lua @@ -10020,7 +10020,7 @@ local options = { cb = 'did_set_wildmode', defaults = 'full', -- Keep this in sync with check_opt_wim(). - values = { 'full', 'longest', 'list', 'lastused' }, + values = { 'full', 'longest', 'list', 'lastused', 'noselect' }, flags = true, deny_duplicates = false, desc = [=[ @@ -10042,7 +10042,10 @@ local options = { "lastused" When completing buffer names and more than one buffer matches, sort buffers by time last used (other than the current buffer). - When there is only a single match, it is fully completed in all cases. + "noselect" Do not pre-select first menu item and start 'wildmenu' + if it is enabled. + When there is only a single match, it is fully completed in all cases + except when "noselect" is present. Examples of useful colon-separated values: "longest:full" Like "longest", but also start 'wildmenu' if it is @@ -10065,7 +10068,11 @@ local options = { set wildmode=list,full < List all matches without completing, then each full match >vim set wildmode=longest,list - < Complete longest common string, then list alternatives. + < Complete longest common string, then list alternatives >vim + set wildmode=noselect:full + < Display 'wildmenu' without completing, then each full match >vim + set wildmode=noselect:lastused,full + < Same as above, but sort buffers by time last used. More info here: |cmdline-completion|. ]=], full_name = 'wildmode', -- cgit