I expected that getcompletion({pat}, 'command') would be able to complete the 2nd word of a command, but it doesn't seem to return any results. For instance:
echo getcompletion('set s', 'command')
returns [] instead of results I would expect like ['set scroll', 'set scrollbind', 'set scrolljump', 'set scrolloff', …].
Is this a bug, or am I using it wrong?
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or unsubscribe.![]()
I expected that
getcompletion({pat}, 'command')would be able to complete the 2nd word of a command, but it doesn't seem to return any results. For instance:echo getcompletion('set s', 'command')returns
[]instead of results I would expect like['set scroll', 'set scrollbind', 'set scrolljump', 'set scrolloff', …].Is this a bug, or am I using it wrong?
Is this a bug, or am I using it wrong?
That's not a bug; command is for names of Ex commands. In set s, s is the start of an option; not the start an Ex command.
I would expect like ['set scroll', 'set scrollbind', 'set scrolljump', 'set scrolloff', …].
Try this:
:vim9 echo getcompletion('set s', 'cmdline')->map((_, v) => 'set s' .. v[1 :])
General case:
vim9script var cmdline: string = 'set s' var start: number = cmdline->matchstr('\S\+$')->strcharlen() echo getcompletion(cmdline, 'cmdline')->map((_, v) => cmdline .. v[start :])
Replace set s with whatever command line you want. For example, with profile f:
vim9script var cmdline: string = 'profile f' var start: number = cmdline->matchstr('\S\+$')->strcharlen() echo getcompletion(cmdline, 'cmdline')->map((_, v) => cmdline .. v[start :])
['profile file', 'profile func']
In the help, I suggest removing the reference to arguments of Ex commands:
diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt index 418aee9ce..fc3d40eef 100644 --- a/runtime/doc/eval.txt +++ b/runtime/doc/eval.txt @@ -5642,7 +5642,7 @@ getcompletion({pat}, {type} [, {filtered}]) *getcompletion()* buffer buffer names behave :behave suboptions color color schemes - command Ex command (and arguments) + command Ex commands cmdline |cmdline-completion| result compiler compilers cscope |:cscope| suboptions
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub.
Triage notifications on the go with GitHub Mobile for iOS or Android.
![]()
Closed #5863.
I'll update the help, thanks for the hint.