grab the output of command complete (C-D)

24 views
Skip to first unread message

Renato Fabbri

unread,
Sep 13, 2019, 7:24:40 AM9/13/19
to vim...@googlegroups.com
I am almost sure I was able to do this...

Example:

:colo <C-D>

shows the available colorschemes.
If I want to have them in a variable,

redir @a
colo ^D
redir END

does not work, in any variation of colo ^D I tried
(exe 'colo ^D', exe 'colo <C-D>', etc).

Help?

--
Renato Fabbri
Computer Science, ICMC-USP

Andy Wokula

unread,
Sep 15, 2019, 12:35:44 PM9/15/19
to vim...@googlegroups.com
Am 13.09.2019 um 13:24 schrieb Renato Fabbri:
> I am almost sure I was able to do this...
>
> Example:
>
> :colo <C-D>
>
> shows the available colorschemes.
> If I want to have them in a variable,
>
> redir @a
> colo ^D
> redir END
>
> does not work, in any variation of colo ^D I tried
> (exe 'colo ^D', exe 'colo <C-D>', etc).
>
> Help?

Newer Vims (7.4.2011 or newer):
:echo getcompletion('', 'color')
=> ['blue', 'darkblue', 'default', 'delek', 'desert', ...]


Older Vims:
:echo ComplList('colo ')

func! ComplList(str)
" {str} partial command-line
let expansion = GetComplAll(a:str)
if a:str =~ '\s'
return split(strpart(expansion, matchend(a:str, '^.*\s')))
else
return split(expansion)
endif
endfunc

func! GetComplAll(str)
" {str} partial command-line
let d = {}
exec "sil norm! :". a:str. "\<C-A>\<C-\>e(extend(d,{'cmdl':getcmdline()}).cmdl)\n"
return get(d, 'cmdl', '')
endfunc

" Credits: ZyX

--
Andy
Reply all
Reply to author
Forward
0 new messages