If your Vim binary includes the patch 8.1.1068, you can use complete_info()
. To get the list of all matches, while the pum is visible, you could use it like this:
map(get(complete_info(['items']), 'items', {}), {_,v -> v.word})
^^^^^^^^^^^^^^^^^^^^^^^^
If your Vim binary also includes 8.1.1803, you can rewrite the expression in a more readable way, using the method call operator:
complete_info(['items'])->get('items', {})->map({_,v -> v.word})
^^ ^^
As an example, this installs a C-x C-x
mapping which – when pressed while the pum is visible – will assign the list of completion matches to the variable g:matches
:
ino <silent> <c-x><c-x> <c-r>=<sid>get_list_of_matches()<cr>
fu s:get_list_of_matches() abort
if ! pumvisible() | return '' | endif
let g:matches = complete_info(['items'])->get('items', {})->map({_,v -> v.word})
return ''
endfu
Instead of assigning the variable manually (via a mapping), you can also assign it automatically, by installing an autocmd listening to the CompleteChanged
event, provided your Vim binary includes 8.1.1138:
augroup get_list_of_matches
au!
au CompleteChanged * let g:matches = complete_info(['items'])->get('items', {})->map({_,v -> v.word})
augroup END
For more info, see:
:h complete_info(
:h CompleteChanged