How to Create a pick (select) list

16 views
Skip to first unread message

Tim Johnson

unread,
Jan 3, 2010, 6:35:15 PM1/3/10
to vim...@googlegroups.com
I'm using gvim 7.2 huge version on ubuntu 9.10.

Is it possible to create a pick list from an internal array?
What I have in mind would be something like i_CTRL-P (word
completion). Only that the pick list would be initialized by
the array.

References to keywords would be a good starting point for research
if the feature is not yet implemented.

thanks
--
Tim
t...@johnsons-web.com
http://www.akwebsoft.com

Christian Brabandt

unread,
Jan 4, 2010, 7:01:58 AM1/4/10
to vim...@googlegroups.com
Hi Tim!

On So, 03 Jan 2010, Tim Johnson wrote:

> Is it possible to create a pick list from an internal array?
> What I have in mind would be something like i_CTRL-P (word
> completion). Only that the pick list would be initialized by
> the array.
>
> References to keywords would be a good starting point for research
> if the feature is not yet implemented.

I would start reading at :h complete-functions.

If you specify in more details, what you want, we can probably figure
something out.

regards,
Christian
--
hundred-and-one symptoms of being an internet addict:
47. You are so familiar with the WWW that you find the search engines useless.

Tom Link

unread,
Jan 4, 2010, 8:15:59 AM1/4/10
to vim_use
> > Is it possible to create a pick list from an internal array?
>
> If you specify in more details, what you want

The key question really is how the OP would like to use the picked
value.

:help complete() has an example for how to use vim's own completion
menu to "pick an item from a list".

An alternative would be to use the popup menu (see :popup) what I have
sometimes used previously. But the handling of the picked item happens
asynchronously, which isn't always what you want.

Now I use (my own) tlib's tlib#input#List(), which allows you to do
something like:

" Single item selection
:echo tlib#input#List('s', 'Select one item', [100,200,300])

or

" Selection of mutliple items
:echo tlib#input#List('m', 'Select one or more item(s)',
[100,200,300])

There are other plugins that achieve similar goals slightly
differently (some of them make use of vim's completion menu, some
don't).

Tom Link

unread,
Jan 4, 2010, 8:24:56 AM1/4/10
to vim_use
> :help complete() has an example for how to use vim's own completion
> menu to "pick an item from a list".

And if the list is short (let's say n < 20), then you could of course
use vim's own inputlist() function, e.g.: echo inputlist(range(20))

Tim Johnson

unread,
Jan 4, 2010, 11:22:43 AM1/4/10
to vim...@googlegroups.com
* Tim Johnson <t...@johnsons-web.com> [100103 14:46]:
<....>
> References to keywords would be a good starting point for research
> if the feature is not yet implemented.
Thanks for all of the input. And all of it was useful.

I tried out inputlist last night and I preferred that to having to
use the mouse to click on something. I will check out the other
references soon.

Cheers

Luc Hermitte

unread,
Jan 11, 2010, 11:59:56 AM1/11/10
to vim use
Hello,

"Tom Link" <mica...@gmail.com> wrote :

> > > Is it possible to create a pick list from an internal array?
> > If you specify in more details, what you want

> [...]


>
> There are other plugins that achieve similar goals slightly
> differently (some of them make use of vim's completion menu, some
> don't).

Indeed.
I have a few functions that help to define asynchronous pick lists. It is not really simple to use as there is a lot of things to specify: the list of items, and the title/question of course, but also the callback to execute, whether multi-selection is supported and so on.

In the past I gave a quick tour of the library: http://www.mail-archive.com/vim...@googlegroups.com/msg04606.html

HTH,

--
Luc Hermitte
http://lh-vim.googlecode.com/
http://hermitte.free.fr/vim/

Reply all
Reply to author
Forward
0 new messages