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 `<Tab>`
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=<C-@> 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("\<C-@>", "ti")
set eventignore+=CmdlineChanged # Suppress redundant completion attempts
timer_start(0, (_) => {
getcmdline()->substitute('\%x00$', '', '')->setcmdline() # Remove <C-@> if no completion items exist
set eventignore-=CmdlineChanged
})
endif
endif
enddef
```
fixes: #16551
closes: #16759
Signed-off-by: Girish Palya <girishji@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
committed by
Christian Brabandt
parent
a250738303
commit
2bacc3e5fb
@ -1,4 +1,4 @@
|
||||
*options.txt* For Vim version 9.1. Last change: 2025 Mar 01
|
||||
*options.txt* For Vim version 9.1. Last change: 2025 Mar 02
|
||||
|
||||
|
||||
VIM REFERENCE MANUAL by Bram Moolenaar
|
||||
@ -9566,7 +9566,10 @@ A jump table for the options with a short description can be found at |Q_op|.
|
||||
"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
|
||||
@ -9589,7 +9592,11 @@ A jump table for the options with a short description can be found at |Q_op|.
|
||||
:set wildmode=list,full
|
||||
< List all matches without completing, then each full match >
|
||||
:set wildmode=longest,list
|
||||
< Complete longest common string, then list alternatives.
|
||||
< Complete longest common string, then list alternatives >
|
||||
:set wildmode=noselect:full
|
||||
< Display 'wildmenu' without completing, then each full match >
|
||||
:set wildmode=noselect:lastused,full
|
||||
< Same as above, but sort buffers by time last used.
|
||||
More info here: |cmdline-completion|.
|
||||
|
||||
*'wildoptions'* *'wop'*
|
||||
|
||||
Reference in New Issue
Block a user