You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
:menu takes a list of labeled commands and allows to select a command to
run with Tab. Almost no other keys are mapped in menu mode.
When there are many menu options, I want to filter the labels with a fuzzy
search, similar to how completions are filtered (in prompt mode).
The notable difference to prompt completions is that menu mode automatically selects
the first option (no need to press Tab).
When filtering, the menu should always select the "next" matching option
(but still allow to cycle with Tab).
Usecase
Some language servers (rust-analyzer) provide many code actions / assists for the cursor position.
It is possible to workaround this by replacing :menu with a command like
the one below, but that doesn't select the first matching option automatically,
making the common case (few code actions) worse.
define-command fake-menu -params 1.. %{
# This is a really convoluted way of saying "menu %arg{@}". The difference is that by using# prompt instead of menu mode, this adds fuzzy search.evaluate-commands%sh{shellquote() {printf"'"printf %s "$1"| sed "s/'/'\\\\''/g; s/§/§§/g; $2"printf"'" } cases= completion= nl=$(printf '\n.'); nl=${nl%.}while [ $#-gt 0 ];do title=$1;shift command=$1;shift completion="${completion}${title}${nl}" cases="${cases}$(shellquote "$title" s/¶/¶¶/g)) printf '%s\\n' $(shellquote "$command" s/¶/¶¶/g) ;;"doneprintf"\ define-command -override fake-menu-menu -params 1 %%§ evaluate-commands %%sh¶ case \"\$1\" in%s *) echo fail no such code action: \"\$1\" ;; esac ¶ §""$cases"| tee /dev/stderrprintf' -shell-script-candidates %%§ printf %%s %s §'"$(shellquote "$completion")"| tee /dev/stderr }execute-keys %{: fake-menu-menu }
}
The text was updated successfully, but these errors were encountered:
Not sure how well this is documented, but :menu can be filtered with the / key that then takes a regex and <c-n> / <c-p> will only cycle through entries that match it.
...but that doesn't select the first matching option automatically...
If you're using a scratch command to provide completion, you can use the -menu switch when defining the command so that if the user hits Enter without typing anything, they get the first option automatically.
Feature
:menu
takes a list of labeled commands and allows to select a command torun with Tab. Almost no other keys are mapped in menu mode.
When there are many menu options, I want to filter the labels with a fuzzy
search, similar to how completions are filtered (in prompt mode).
The notable difference to prompt completions is that menu mode automatically selects
the first option (no need to press Tab).
When filtering, the menu should always select the "next" matching option
(but still allow to cycle with Tab).
Usecase
Some language servers (rust-analyzer) provide many code actions / assists for the cursor position.
It is possible to workaround this by replacing
:menu
with a command likethe one below, but that doesn't select the first matching option automatically,
making the common case (few code actions) worse.
The text was updated successfully, but these errors were encountered: