mirror of
https://github.com/neovim/neovim.git
synced 2025-09-29 14:38:32 +00:00

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
2bacc3e5fb
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>
49 lines
1.4 KiB
C
49 lines
1.4 KiB
C
#pragma once
|
|
|
|
#include "nvim/cmdexpand_defs.h" // IWYU pragma: keep
|
|
#include "nvim/eval/typval_defs.h" // IWYU pragma: keep
|
|
#include "nvim/ex_getln_defs.h" // IWYU pragma: keep
|
|
#include "nvim/garray_defs.h" // IWYU pragma: keep
|
|
#include "nvim/regexp_defs.h" // IWYU pragma: keep
|
|
#include "nvim/types_defs.h" // IWYU pragma: keep
|
|
|
|
// Values for nextwild() and ExpandOne(). See ExpandOne() for meaning.
|
|
|
|
enum {
|
|
WILD_FREE = 1,
|
|
WILD_EXPAND_FREE = 2,
|
|
WILD_EXPAND_KEEP = 3,
|
|
WILD_NEXT = 4,
|
|
WILD_PREV = 5,
|
|
WILD_ALL = 6,
|
|
WILD_LONGEST = 7,
|
|
WILD_ALL_KEEP = 8,
|
|
WILD_CANCEL = 9,
|
|
WILD_APPLY = 10,
|
|
WILD_PAGEUP = 11,
|
|
WILD_PAGEDOWN = 12,
|
|
WILD_PUM_WANT = 13,
|
|
};
|
|
|
|
enum {
|
|
WILD_LIST_NOTFOUND = 0x01,
|
|
WILD_HOME_REPLACE = 0x02,
|
|
WILD_USE_NL = 0x04,
|
|
WILD_NO_BEEP = 0x08,
|
|
WILD_ADD_SLASH = 0x10,
|
|
WILD_KEEP_ALL = 0x20,
|
|
WILD_SILENT = 0x40,
|
|
WILD_ESCAPE = 0x80,
|
|
WILD_ICASE = 0x100,
|
|
WILD_ALLLINKS = 0x200,
|
|
WILD_IGNORE_COMPLETESLASH = 0x400,
|
|
WILD_NOERROR = 0x800, ///< sets EW_NOERROR
|
|
WILD_BUFLASTUSED = 0x1000,
|
|
BUF_DIFF_FILTER = 0x2000,
|
|
WILD_KEEP_SOLE_ITEM = 0x4000,
|
|
};
|
|
|
|
#ifdef INCLUDE_GENERATED_DECLARATIONS
|
|
# include "cmdexpand.h.generated.h"
|
|
#endif
|