vim/runtime
Girish Palya 2bacc3e5fb
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>
2025-03-02 23:02:42 +01:00
..
autoload runtime(tar): use readblob() instead of shelling out to file(1) 2025-03-02 22:24:28 +01:00
bitmaps
colors runtime(colors): Update colorschemes, include new unokai colorscheme 2025-01-14 17:15:59 +01:00
compiler runtime(compiler): improve svelte-check 2025-02-27 19:09:52 +01:00
doc patch 9.1.1166: command-line auto-completion hard with wildmenu 2025-03-02 23:02:42 +01:00
ftplugin runtime(lua): Improve 'include' and make '*expr' functions script-local 2025-02-27 19:17:33 +01:00
icons
import/dist
indent patch 9.1.1140: filetype: m17ndb files are not detected 2025-02-23 09:41:42 +01:00
keymap runtime(keymap): Add ukrainian-enhanced keymap 2025-02-15 09:59:57 +01:00
lang
macros
pack/dist/opt runtime(netrw): correctly handle shellslash variable 2025-02-28 17:30:25 +01:00
plugin runtime(misc): add support for bzip3 to tar, vimball and gzip plugins 2025-02-28 18:06:14 +01:00
print
spell
syntax runtime(syntax-tests): Apply stronger synchronisation between buffers 2025-03-01 16:28:20 +01:00
tools
tutor runtime(new-tutor): update examples from Neovim to Vim 2025-02-26 19:00:48 +01:00
bugreport.vim
defaults.vim
delmenu.vim
doc.info
evim.vim
filetype.vim patch 9.1.1140: filetype: m17ndb files are not detected 2025-02-23 09:41:42 +01:00
ftoff.vim
ftplugin.vim
ftplugof.vim
gvim.desktop
gvimrc_example.vim
hi16-action-make.png
hi22-action-make.png
icons.info
indent.vim
indoff.vim
macmap.vim
macros.info
makemenu.vim
menu.vim
mswin.vim
optwin.vim patch 9.1.1084: Unable to persistently ignore events in a window and its buffers 2025-02-08 18:52:39 +01:00
scripts.vim
synmenu.vim
termcap
tools.info
tutor.info
vim.desktop
vim16x16.gif
vim16x16.png
vim16x16.xpm
vim32x32.gif
vim32x32.png
vim32x32.xpm
vim48x48.gif
vim48x48.png
vim48x48.xpm
vimlogo.cdr
vimlogo.eps
vimlogo.gif
vimlogo.pdf
vimlogo.svg
vimlogo.xpm
vimrc_example.vim