-
-
Notifications
You must be signed in to change notification settings - Fork 5.9k
Feat: Add wildtrigger() function for command-line autocompletion #17806
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
@habamax can you test this please? Is this what you need? |
This PR introduces a new `wildtrigger()` function. See `:h wildtrigger()` `wildtrigger()` behaves like pressing the `wildchar,` but provides a more refined and controlled completion experience: - Suppresses beeps when no matches are found. - Avoids displaying irrelevant completions (like full command lists) when the prefix is insufficient or doesn't match. - Skips completion if the typeahead buffer has pending input or if a wildmenu is already active. - Does not print "..." before completion. This is an improvement on the `feedkeys()` based autocompletion script given in vim#16759. M runtime/doc/builtin.txt M runtime/doc/cmdline.txt M runtime/doc/options.txt M runtime/doc/tags M runtime/doc/usr_41.txt M src/cmdexpand.c M src/evalfunc.c M src/ex_getln.c M src/keymap.h M src/proto/ex_getln.pro M src/testdir/test_cmdline.vim M src/vim.h
Have just tried it and it looks like it simplifies the setup quite a bit:
|
|
@dkearns |
Co-authored-by: zeertzjq <zeertzjq@outlook.com>
|
thanks |
Problem: cannot easily trigger wildcard expansion
Solution: Introduce wildtrigger() function
(Girish Palya)
This PR introduces a new `wildtrigger()` function.
See `:h wildtrigger()`
`wildtrigger()` behaves like pressing the `wildchar,` but provides a
more refined and controlled completion experience:
- Suppresses beeps when no matches are found.
- Avoids displaying irrelevant completions (like full command lists)
when the prefix is insufficient or doesn't match.
- Skips completion if the typeahead buffer has pending input or if a
wildmenu is already active.
- Does not print "..." before completion.
This is an improvement on the `feedkeys()` based autocompletion script
given in vim/vim#16759.
closes: vim/vim#17806
vim/vim@b486ed8
While at it, also make Ctrl-Z trigger search completion.
Co-authored-by: Girish Palya <girishji@gmail.com>
Problem: cannot easily trigger wildcard expansion
Solution: Introduce wildtrigger() function
(Girish Palya)
This PR introduces a new `wildtrigger()` function.
See `:h wildtrigger()`
`wildtrigger()` behaves like pressing the `wildchar,` but provides a
more refined and controlled completion experience:
- Suppresses beeps when no matches are found.
- Avoids displaying irrelevant completions (like full command lists)
when the prefix is insufficient or doesn't match.
- Skips completion if the typeahead buffer has pending input or if a
wildmenu is already active.
- Does not print "..." before completion.
This is an improvement on the `feedkeys()` based autocompletion script
given in vim/vim#16759.
closes: vim/vim#17806
vim/vim@b486ed8
While at it, also make Ctrl-Z trigger search completion.
Co-authored-by: Girish Palya <girishji@gmail.com>
Problem: cannot easily trigger wildcard expansion
Solution: Introduce wildtrigger() function
(Girish Palya)
This PR introduces a new `wildtrigger()` function.
See `:h wildtrigger()`
`wildtrigger()` behaves like pressing the `wildchar,` but provides a
more refined and controlled completion experience:
- Suppresses beeps when no matches are found.
- Avoids displaying irrelevant completions (like full command lists)
when the prefix is insufficient or doesn't match.
- Skips completion if the typeahead buffer has pending input or if a
wildmenu is already active.
- Does not print "..." before completion.
This is an improvement on the `feedkeys()` based autocompletion script
given in vim/vim#16759.
closes: vim/vim#17806
vim/vim@b486ed8
While at it, also make Ctrl-Z trigger search completion.
Co-authored-by: Girish Palya <girishji@gmail.com>
|
Thanks |
|
@girishji do you think there should be room for improvements wrt |
|
No need for that function. See |
|
Also, please test for any jitteriness (e.g., unnecessary redraws) on the command-line. One known limitation that I do not intend to fix is that the popup menu is always cleared before being redrawn, causing a brief "blink" even when its position remains unchanged and only a few items have changed. |
|
Oh, I missed that part, great!
Unnecessary redraws are there but it is not that of a big deal. |
Problem: cannot easily trigger wildcard expansion
Solution: Introduce wildtrigger() function
(Girish Palya)
This PR introduces a new `wildtrigger()` function.
See `:h wildtrigger()`
`wildtrigger()` behaves like pressing the `wildchar,` but provides a
more refined and controlled completion experience:
- Suppresses beeps when no matches are found.
- Avoids displaying irrelevant completions (like full command lists)
when the prefix is insufficient or doesn't match.
- Skips completion if the typeahead buffer has pending input or if a
wildmenu is already active.
- Does not print "..." before completion.
This is an improvement on the `feedkeys()` based autocompletion script
given in vim/vim#16759.
closes: vim/vim#17806
vim/vim@b486ed8
While at it, also make Ctrl-Z trigger search completion.
Co-authored-by: Girish Palya <girishji@gmail.com>
|
@girishji do you know if there is a way to detect if command-line was canceled with The use case is with auto-selecting the first item in the popup menu for some of the commands, in your example, it would be Here if you press |
|
What triggered |
Yes, this would work for custom commands, but I also have similar things for existing commands too (find, buffer, etc): And it lets me have the same experience with https://asciinema.org/a/iSgzDSCK5dJXNmd422BlwzJ44 But as you confirmed, we don't have anything like that. I would need to think if I can get some kind of workaround or just live with it. PS, I wonder if |
It's possible. Maybe a better solution is to have a boolean option |
|
For some of the commands I would like to have it, for some not. But maybe you will have an implementation where we would be able to iron out edge cases. |
Can you explain? For what commands would you not have it. |
|
For commands themselves I think. Like if I do :q it shouldn’t accept first command from popup. And I need to refresh memory why I accept first menu items only for some of the commands. |
|
Makes sense. There are 2 optons:
|
When I do |
|
Fair enough. Using |
|
I am currently comparing list of commands with |
|
I looked into this. Implementing an option that accepts a list is fairly straightforward. However, that would leave us with two different ways to achieve the same result. A better approach might be to add an entry to the dictionary returned by |
|
yes, that is another way to get it, something that will give us Although I think that But as I said, any way to get it would be fine for me :) |
Problem: unclear what key causes CmdlineLeave autocommand Solution: Set |v:char| to the key (Girish Palya). related: vim/vim#17806 closes: vim/vim#18063 vim/vim@ba9551d Co-authored-by: Girish Palya <girishji@gmail.com>
Problem: unclear what key causes CmdlineLeave autocommand Solution: Set |v:char| to the key (Girish Palya). related: vim/vim#17806 closes: vim/vim#18063 vim/vim@ba9551d Co-authored-by: Girish Palya <girishji@gmail.com>
…35677) Problem: unclear what key causes CmdlineLeave autocommand Solution: Set |v:char| to the key (Girish Palya). related: vim/vim#17806 closes: vim/vim#18063 vim/vim@ba9551d Co-authored-by: Girish Palya <girishji@gmail.com>
…35022) Problem: cannot easily trigger wildcard expansion Solution: Introduce wildtrigger() function (Girish Palya) This PR introduces a new `wildtrigger()` function. See `:h wildtrigger()` `wildtrigger()` behaves like pressing the `wildchar,` but provides a more refined and controlled completion experience: - Suppresses beeps when no matches are found. - Avoids displaying irrelevant completions (like full command lists) when the prefix is insufficient or doesn't match. - Skips completion if the typeahead buffer has pending input or if a wildmenu is already active. - Does not print "..." before completion. This is an improvement on the `feedkeys()` based autocompletion script given in vim/vim#16759. closes: vim/vim#17806 vim/vim@b486ed8 While at it, also make Ctrl-Z trigger search completion. Co-authored-by: Girish Palya <girishji@gmail.com>
…eovim#35677) Problem: unclear what key causes CmdlineLeave autocommand Solution: Set |v:char| to the key (Girish Palya). related: vim/vim#17806 closes: vim/vim#18063 vim/vim@ba9551d Co-authored-by: Girish Palya <girishji@gmail.com>

This PR introduces a new
wildtrigger()function.See
:h wildtrigger()(diffs inbuiltin.txtfor how to enable command-line autocompletion).wildtrigger()behaves like pressing thewildchar,but provides a more refined and controlled completion experience:This is an improvement on the
feedkeys()based autocompletion script given in #16759.Added:
Beyond reducing the amount of typing, autocompletion system can be used to build fuzzy pickers and interactive command interfaces. Below are two examples:
Fuzzy file picker: Transforms the native
:findcommand into a fzf-like experience.Live grep: Dynamically search and display matching lines as you type.
Auto-select the first item in the completion list, and (in case of grep) add the typed pattern into the command-line history:
NOTE: It's usually not necessary to make these commands asynchronous using
job_start()and polling for input withgetchar(), as they perform well enough for typical use cases.