diff options
author | Tomas Slusny <slusnucky@gmail.com> | 2025-03-03 17:51:42 +0100 |
---|---|---|
committer | zeertzjq <zeertzjq@outlook.com> | 2025-03-04 06:20:20 +0800 |
commit | 99d688e6459c7963b00a95d544de7a3de951a70b (patch) | |
tree | e984f5121dddf2fbf462c31a3d1a7941482ed119 /src/nvim/cmdexpand.c | |
parent | 948179cb19c75a9e79cdf2c86c441304c5285e81 (diff) | |
download | rneovim-99d688e6459c7963b00a95d544de7a3de951a70b.tar.gz rneovim-99d688e6459c7963b00a95d544de7a3de951a70b.tar.bz2 rneovim-99d688e6459c7963b00a95d544de7a3de951a70b.zip |
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 `<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: 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 <girishji@gmail.com>
Signed-off-by: Tomas Slusny <slusnucky@gmail.com>
Diffstat (limited to 'src/nvim/cmdexpand.c')
-rw-r--r-- | src/nvim/cmdexpand.c | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/src/nvim/cmdexpand.c b/src/nvim/cmdexpand.c index 33ccc834d2..fcfeda5482 100644 --- a/src/nvim/cmdexpand.c +++ b/src/nvim/cmdexpand.c @@ -288,7 +288,7 @@ int nextwild(expand_T *xp, int type, int options, bool escape) p1 = addstar(xp->xp_pattern, xp->xp_pattern_len, xp->xp_context); } // Translate string into pattern and expand it. - const int use_options = (options + const int use_options = ((options & ~WILD_KEEP_SOLE_ITEM) | WILD_HOME_REPLACE | WILD_ADD_SLASH | WILD_SILENT @@ -339,7 +339,7 @@ int nextwild(expand_T *xp, int type, int options, bool escape) if (xp->xp_numfiles <= 0 && p2 == NULL) { beep_flush(); - } else if (xp->xp_numfiles == 1) { + } else if (xp->xp_numfiles == 1 && !(options & WILD_KEEP_SOLE_ITEM)) { // free expanded pattern ExpandOne(xp, NULL, NULL, 0, WILD_FREE); } |