1 " The following variable configures the way |tlib#input#ListD()| works.
2 " In this example, we allow selection of multiple items (we could also
3 " allow only a single choice and make |tlib#input#ListD()| work on the
4 " indices, not the items).
6 " We also set a prompt that will be displayed in the command area.
8 " By default, |tlib#input#ListD()| will automatically select an item if
9 " there is only one item left matching the filter. In this example, we
10 " disable this feature.
12 " For demonstration purposes, we also define a key handler that prints
16 \ 'query': 'Select lines for command output',
17 \ 'pick_last_item': 0,
19 \ {'key': 16, 'agent': 'PrintMe', 'key_name': '<c-p>', 'help': 'Print line'},
23 " A key handler takes two arguments: the current state of the list
24 " display and a list of selected items/indices (depending on the type
26 function! PrintMe(state, items) "{{{3
31 call input("Press ENTER to continue")
32 let a:state.state = 'redisplay'
36 " In this example, we evaluate an ex-command with |:execute| and display
37 " the command's output as list. The user can select certain lines by
38 " typing some pattern or by pressing <a-NUMBER> to select an item by
39 " number. The user can then press <c-p> to print the lines (see above)
40 " or <cr> to pick the selected lines.
41 function! SelectOutput(ex) "{{{3
45 let state = copy(s:state)
46 let state.base = split(lines, '\n')
47 let picked = tlib#input#ListD(state)
48 echom "You picked: ". join(picked, ', ')