Wikia

Vim Tips Wiki

Get ex command line completion as a list

Talk0
1,613pages on
this wiki

Proposed tip Please edit this page to improve it, or add your comments below (do not use the discussion page).

Please use new tips to discuss whether this page should be a permanent tip, or whether it should be merged to an existing tip.
created January 10, 2014 · complexity basic · author Majkinetor · version 7.0

This function obtains the list of possible command line items—those that are visible in wildmenu. It uses Ctrl-a (:help c_CTRL-A) to obtain the info and the fact that it will be inserted in command line history ASAP where last line is yanked and cmd history closed with <c-f> yy o <cr>

function! GetCmdCompletion(cmd_prefix)
  let [cwh,ls,v] = [&cwh, &ls, @v]
  set cwh=1 ls=0
  execute 'nn <buffer> z&u :' . a:cmd_prefix . '<c-a><c-f>"vyyo<cr>'
  normal z&u
  let res = split(@v)
  let [&cwh,&ls,@v] = [cwh,ls,v]
  return res
endfunction

This may be used as a source to some plugins (i.e. unite).

This function puts a large amount of text in Vim's command line (depending on the number of completion items). This is not an important issue for single call of the above function but several calls would make this behavior problematic. I didn't find the way to hide Vim's command line or limit the amount of text it displays so far.

CommentsEdit

https://github.com/MarcWeber/vim-addon-commandline-completion is a related implementation which provides tlib based completion this way

Around Wikia's network

Random Wiki