Search code examples
vimfile-browser

Select a directory in vim and use it's name in function call


Inside a vim function I would like to have the user select a directory (instead of writing its name), I guess using :Explore, then get the filename of that directory and pass it to another function for example.

E.g. something like this

function! Test()
    let directory = ????
    call Test2(directory)
endfunction

Solution

  • This can be achieved with the browsedir() function:

    function! Test()
       let initialDir = '/home/'
       let directory = browsedir('my prompt title', initialDir)
       echo "directory = ".directory
    endfunction