-
Notifications
You must be signed in to change notification settings - Fork 414
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
Select nth item in the completion list, and number items #1491
base: main
Are you sure you want to change the base?
Conversation
I think it can be supported via |
I really appreciate the contribution, but I'm not really a fan of this feature. . . Can you tell us about the superiority of this function? |
If you could give me an example of that, I'd love to see it. I did try that first, and couldn't come up with one that meets the following requirements:
The use case here is binding say "alt + 1/2/3/..." to select the 1st/2nd/3rd/... item in the completion menu so if you start typing, and see the item you want in the 5th slot just hitting "alt + 5" lets you immediately select it. Additionally, if you're on the 5th item, and want to jump to the 7th item, hitting "alt + 7" still works, this is in contrast to a solution which uses I've found bindings like this (in conjunction with the numbers) especially useful in completing text that's already in the buffer. When typing a css class like "selectable-item", there are often other words that get suggested first, but it's very easy to pick that out from a list, identify the number, and immediately select it. |
@hrsh7th any comment here? |
This is an interesting idea. I see the benefit, although not sure if it's a large/necessary one. I do feel like it's possible to pull this off currently (probably via a manual "hacky" solution), but not easily. If the maintainer doesn't want this, perhaps it should be made into a plugin to save users from having to repeat the same hack. |
The non-hacky solution for me is to just a branch of my fork onto main whenever I remember. Beauty of open source :P Seriously though if you think there's a way to get this to work with an external plugin I'd be happy to hear it. The only way I could think to do it would be adding a floating window that shows up next to the completion menu to display the numbers and then you could setup some bindings that press but I'm not willing to implement that honestly |
I would like to have this in the core, or through another plugin is also fine. |
Personally like this as it would support my usecase of Currently solving like this: mapping = cmp.mapping.preset.insert {
...
-- jump to top
['<C-k>'] = cmp.mapping(function()
cmp.select_prev_item({
count = indexOf(cmp.get_entries(), cmp.get_selected_entry()) - 1
})
end),
-- jump to bottom
['<C-j>'] = cmp.mapping(function()
cmp.select_next_item({
count = (
--length of get_entries - index of selected entry
#cmp.get_entries() -
indexOf(cmp.get_entries(), cmp.get_selected_entry())
)
})
end),
...
} |
I would just like to add a voice that I think this is a useful feature for beginners (like myself). The ability to press a number, and be able to immediately get a result, is really nice. Perhaps there would be a way of integrating the feature, without disrupting what regular users are used to? |
Also very much a fan of this feature! 🔥 It is really quite good when you see the match you want, to be able to just pick it instead of figuring out which characters to type more to make it at the top. @benlubas thank you very much for your work on this! @hrsh7th hopefully you can reconsider adding it to the core or help on how to make a plugin for it. |
Instead of leaving more comments, if you like this PR just give it a thumbs up please. |
At the risk of more noise - this PR is also very useful for implementing "supertab"- like functionality (ala sublime text)! With supertab bindings (LazyVim/lazyvim.github.io#113), I can quickly look at the number next to the completion I want to select ( Would be great to have this merged :) Also, this feature was requested a while ago for screen readers but hasn't been mentioned yet in this thread -- another usecase for this feature 👍 #1112 wezterm-gui_08RbGRlUNa.mp4 |
Using select_next_item and Does anyone know how to get the index of the entry? |
As discussed in #1482 being able to press alt + n to select the nth item in the completion list would be pretty cool. Unfortunately there is not a great way to implement that right now, and there's (as far as I could tell) no way to number the items in the completion menu. This PR is the result of that.
Adds a format
field
for numbersI've accounted for scrolling, and the completion list being flipped.
Adds
cmp.select_nth(n)
which selects the nth item in the completion list.This allows for bindings to select items like the following:
Important improvement here,
select_nth(4)
will always select the item labeled4
. Like the numbers, this works when the completion list is scrolled, and when the list is flipped.Things this doesn't do:
select_nth
doesn't appear to work in command line completion.If this gets accepted, I plan to add a wiki page detailing how to setup binds like this, with a section for macos users, b/c alt + 1 on macos by default types some symbol or another.