Search code examples
inputvimdialog

Combine options in inputdialog


I often use the inputdialog to execute a command using:

  let n = confirm({msg} [, {choices} [, {default} [, {type}]]])

p.e. search numbers
if n == 1 --> p.e. do search of all numbers with '.,'
if n == 2 --> p.e. do search of all exponential numbers
if n == 3 --> p.e. do search of all numbers with 3 digits
etc

but with this method I can only choose one argument.

Is there a way in Vim where you can chose multiple arguments together in an inputdialog?


Solution

  • A workaround, use input() function, let the user to choose multiple options and split them into a list to process them. An example:

    Add next function to vimrc or similar file:

    func My_search()
        let my_grouped_opts = input ( "1.- Search one\n2.- Search two\n3.- Search three\n" )
        let my_list_opts = split( my_grouped_opts, '.\zs' )
        for opt in my_list_opts
            echo "Option number " opt " selected"
        endfor
    endfunction
    

    Call it:

    :call My_search()
    

    There will appear your options:

    1.- Search one
    2.- Search two
    3.- Search three
    

    Select them like:

    23
    

    And the function will split them into a list.