[vim/vim] getcompletion for command type doesn't seem to complete multiple words (#5863)

13 views
Skip to first unread message

David Barnett

unread,
Mar 28, 2020, 8:35:54 PM3/28/20
to vim/vim, Subscribed

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.

Yegappan Lakshmanan

unread,
Mar 28, 2020, 8:42:49 PM3/28/20
to vim_dev, reply+ACY5DGEQYFZTFIYXIE...@reply.github.com, vim/vim, Subscribed
Hi,

On Sat, Mar 28, 2020 at 5:35 PM David Barnett <vim-dev...@256bit.org> wrote:

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 need to use getcompletion('s', 'option') to return the list of options starting
with 's'. The 'command' option for getcompletion() is used to get the list of
ex commands start with the specified prefix.

- Yegappan
 

vim-dev ML

unread,
Mar 28, 2020, 8:43:05 PM3/28/20
to vim/vim, vim-dev ML, Your activity

Hi,

On Sat, Mar 28, 2020 at 5:35 PM David Barnett <vim-dev...@256bit.org>
wrote:

> 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 need to use getcompletion('s', 'option') to return the list of options
starting
with 's'. The 'command' option for getcompletion() is used to get the list
of
ex commands start with the specified prefix.

- Yegappan

lacygoill

unread,
Nov 2, 2021, 2:39:45 PM11/2/21
to vim/vim, vim-dev ML, Comment

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.

Christian Brabandt

unread,
Nov 2, 2021, 4:45:20 PM11/2/21
to vim/vim, vim-dev ML, Comment

Closed #5863.

Bram Moolenaar

unread,
Nov 4, 2021, 7:13:04 AM11/4/21
to vim/vim, vim-dev ML, Comment

I'll update the help, thanks for the hint.

Reply all
Reply to author
Forward
0 new messages